Twitter integration stopped working recently - twitter

This was the code, I was using but it has stopped working. Get anyone help me to solve this as I dont have much knowledge about this.
// JQuery Twitter Feed. Coded by www.tom-elliott.net (2012) and modified from https://twitter.com/javascripts/blogger.js
var p = jQuery.noConflict();
p(document).ready(function () {
var twitterprofile = "waateanews";
var hidereplies = true;
var showretweets = true;
var showtweetlinks = true;
var displayLimit = 3;
p.getJSON('https://api.twitter.com/1/statuses/user_timeline/'+twitterprofile+'.json?include_rts='+showretweets+'&exclude_replies='+hidereplies+'&count=30&callback=?',
function(feeds) {
var feedHTML = '';
var displayCounter = 1;
for (var i=0; i<feeds.length; i++) {
var username = feeds[i].user.screen_name;
var profileimage = feeds[i].user.profile_image_url_https;
var status = feeds[i].text;
if ((feeds[i].text.length > 1) && (displayCounter <= displayLimit)) {
if (showtweetlinks == true) {
status = addlinks(status);
}
if (displayCounter == 1) {
//feedHTML += '<h1>#'+twitterprofile+' on Twitter</h1>';
}
feedHTML += '<div class="twitter-article">';
feedHTML += '<div class="twitter-pic"><img src="'+profileimage+'"images/twitter-feed-icon.png" width="42" height="42" alt="twitter icon" /></div>';
feedHTML += '<div class="twitter-text"><p>'+status+'<br/><span class="tweet-time">'+relative_time(feeds[i].created_at)+'</span></p></div>';
feedHTML += '</div>';
displayCounter++;
}
}
p('#twitter-feed').html(feedHTML);
});
function addlinks(data) {
//Add link to all http:// links within tweets
data = data.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
return ''+url+'';
});
//Add link to #usernames used within tweets
data = data.replace(/\B#([_a-z0-9]+)/ig, function(reply) {
return ''+reply.charAt(0)+reply.substring(1)+'';
});
return data;
}
function relative_time(time_value) {
var values = time_value.split(" ");
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
delta = delta + (relative_to.getTimezoneOffset() * 60);
if (delta < 60) {
return 'less than a minute ago';
} else if(delta < 120) {
return 'about a minute ago';
} else if(delta < (60*60)) {
return (parseInt(delta / 60)).toString() + ' minutes ago';
} else if(delta < (120*60)) {
return 'about an hour ago';
} else if(delta < (24*60*60)) {
return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
} else if(delta < (48*60*60)) {
return '1 day ago';
} else {
return (parseInt(delta / 86400)).toString() + ' days ago';
}
}
});
</script>
<div id="twitter-feed"></div>
<div id="twitter_footer">Follow us on twitter</div>

Twitter has retired the API v1. Details here. You will have to rewrite the code to use oAuth or use some ready made scripts. I will let you figure that out.

Related

Loop recurring formula

I want to add a recurring formula to my script for a timesheet wherein when I punch out it will calculate the duration of Time In and Time out, then it would lock the values of time in and out and the total duration. Thank you in advance if you would help me out.
function setValue(cellName, value) {
SpreadsheetApp.getActiveSpreadsheet().getRange(cellName).setValue(value);
}
function getValue(cellName) {
return SpreadsheetApp.getActiveSpreadsheet().getRange(cellName).getValue();
}
function getNextRow() {
return SpreadsheetApp.getActiveSpreadsheet().getLastRow() + 1;
}
function getNextRow2() {
return SpreadsheetApp.getActiveSpreadsheet().getLastRow() + 2;
}
function setUser1(x) {
setValue('I1', 'User 1');
}
function setUser2() {
setValue('I1', 'User 2');
}
function addRecord(a, b, c) {
var row = getNextRow();
setValue('A' + row, a);
setValue('B' + row, b);
setValue('C' + row, c);
}
function isUserIn(user) {
var lastRow = SpreadsheetApp.getActiveSheet().getLastRow();
for (var i = lastRow; i >= 1; i--) {
if (getValue("A" + i) == user) {
if (getValue("C" + i) > getValue("B" + i)) {
return false;
}
return true;
}
}
}
function punchIN() {
var user = getValue("I1");
var lastRow = SpreadsheetApp.getActiveSheet().getLastRow();
addRecord(getValue('I1'), new Date());
}
function punchOut() {
var user = getValue("I1");
var lastRow = SpreadsheetApp.getActiveSheet().getLastRow();
if (isUserIn(user)) {
for (var i = lastRow; i >= 1; i--) {
if (getValue("A" + i) == user) {
if (getValue("C" + i) == "") {
setValue("C" + i, new Date(), "IN");
}
}
}
}
}
it should basically look like this
enter image description here
Please help me do this thanks. I actually have no background in coding it would be a big help if someone could help me with this.
Modify your punchout() function as follow:
function punchOut() {
var user = getValue("I1");
var lastRow = SpreadsheetApp.getActiveSheet().getLastRow();
if (isUserIn(user)) {
for (var i = lastRow; i >= 1; i--) {
if (getValue("A" + i) == user) {
if (getValue("C" + i) == "") {
setValue("C" + i, new Date());
var duration = (getValue("C" + i) - getValue("B" + i)) / (60 * 60 * 1000);
setValue("D" + i, duration);
SpreadsheetApp.getActiveSheet().getRange("B" + i + ":C" + i).setLocked(true);
break;
}
}
}
}
}
Also you can modify your getNextRow is follow:
function getNextNRow(n) {
return SpreadsheetApp.getActiveSpreadsheet().getLastRow() + n;
}

Not able to use the updated value -- Flutter

I'm updating the totalPayable value in else if, but I'm not able to use the updated value anywhere in the code when I call getOrder(). Is it an API problem or what can anyone help me with the code?
else if (isOrderInitiated == false){
getCleintOrderFromApi();
debugPrint("ifelse" + totalPayable.toString());
}
getClientOrderFromApi() {
orders.clear();
totalPayable = 0.0;
api.getCleintOrder().then((list) {
list.forEach((order) {
if(order.is_placed) {
order.status = ORDER_STATUS[0];
} else if(!order.is_placed) {
order.status = ORDER_STATUS[2];
}
debugPrint("ORDER_STATUS from remote" + order.status);
for (var j = 0; j < order.items.length; j++) {
FoodItemOrder item = order.items[j];
totalPayable = totalPayable + item.unitPrice * item.quantity;
debugPrint(" total payable in order "+ totalPayable.toString());
}
orders.add(order);
debugPrint("itemsin order"+orders.last.items.length.toString());
});
currentOrderList.clear();
currentOrderList.addAll(orders);
orderItemsSink.add(orders);
});
}
}
The debugPrint in getClientOrderFromApi() is showing the updated result, but in else if debugPrint(" ifelse "+ totalPayable.toString()); it is not showing the updated value which is why wherever I use totalPayable it is not showing the desired value.
Future<List<Order>> getCleintOrder() async {
MakeOrder clientOrderRequest = MakeOrder(); //currentCafe;
clientOrderRequest.caffeID = currentCafe.caffeId;
clientOrderRequest.tableidtimestamp = currentUser.tableIdTimestamp;
// offset = 160;
String url = BASE_URL + BASE_URL_GET_CLIENT_ORDER;
debugPrint("requesting getCleintOrder --- \n" +
url +
"\n " +
clientOrderRequest.toClietnOrderJson().toString());
var response = await http
.post(
url,
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
// HttpHeaders.authorizationHeader : ''
},
body: json.encode(clientOrderRequest.toClietnOrderJson()),
)
.catchError(
(error) {
////debugPrint(error.toString());
return false;
},
);
var jsonObj = json.decode(response.body);
////debugPrint(jsonObj.toString());
List<Order> orders = [];
try {
jsonObj.forEach((newJson) {
List<Order> orderList = (newJson["orders"] as List)
.map((neworderJson) => Order.fromJSON(neworderJson))
.toList().cast<Order>();
orders.addAll(orderList);
});
} catch (e) {
////debugPrint(e.toString());
}
// debugPrint("total client orders " + orders.length.toString());
return orders;
}
This is my api call for refernece.

Cant stream video (PFFile) from parse server

I am having trouble streaming video with my iOS app from URL of a PFFile uploaded in my database. I used Heroku and AWS and I still have the same issue. It used to work fine when the files were hosted in the old parse server.
the PFFile url works fine when I open it in a chrome web browser but not in safari nor in the iOS app.
the following is the link of the video:
http://shuuapp.herokuapp.com/parse/files/wnQeou0L4klDelSEtMOX6SxXRVKu1f3sKl6vg349/24092609eadcc049f711aafbd59c1a18_movie.mp4
Its exactly the same issue as the issue mentioned in the link below:
iOS - Can't stream video from Parse Backend
parse-server doesn't seem to be supporting streaming in Safari/iOS and the solution is the enable it using express & GridStore as follows,
parse-server-example\node_modules\parse-server\lib\Routers\FilesRouter
{
key: 'getHandler',
value: function getHandler(req, res, content) {
var config = new _Config2.default(req.params.appId);
var filesController = config.filesController;
var filename = req.params.filename;
var video = '.mp4'
var lastFourCharacters = video.substr(video.length - 4);
if (lastFourCharacters == '.mp4') {
filesController.handleVideoStream(req, res, filename).then(function (data) {
}).catch(function (err) {
console.log('404FilesRouter');
res.status(404);
res.set('Content-Type', 'text/plain');
res.end('File not found.');
});
}else{
filesController.getFileData(config, filename).then(function (data) {
res.status(200);
res.end(data);
}).catch(function (err) {
res.status(404);
res.set('Content-Type', 'text/plain');
res.end('File not found.');
});
}
}
} , ...
parse-server-example\node_modules\parse-server\lib\Controllers\FilesController
_createClass(FilesController, [{
key: 'getFileData',
value: function getFileData(config, filename) {
return this.adapter.getFileData(filename);
}
},{
key: 'handleVideoStream',
value: function handleVideoStream(req, res, filename) {
return this.adapter.handleVideoStream(req, res, filename);
}
}, ...
parse-server-example\node_modules\parse-server\lib\Adapters\Files\GridStoreAdapter
... , {
key: 'handleVideoStream',
value: function handleVideoStream(req, res, filename) {
return this._connect().then(function (database) {
return _mongodb.GridStore.exist(database, filename).then(function () {
var gridStore = new _mongodb.GridStore(database, filename, 'r');
gridStore.open(function(err, GridFile) {
if(!GridFile) {
res.send(404,'Not Found');
return;
}
console.log('filename');
StreamGridFile(GridFile, req, res);
});
});
})
}
}, ...
Bottom of GridStore Adapter
function StreamGridFile(GridFile, req, res) {
var buffer_size = 1024 * 1024;//1024Kb
if (req.get('Range') != null) { //was: if(req.headers['range'])
// Range request, partialle stream the file
console.log('Range Request');
var parts = req.get('Range').replace(/bytes=/, "").split("-");
var partialstart = parts[0];
var partialend = parts[1];
var start = partialstart ? parseInt(partialstart, 10) : 0;
var end = partialend ? parseInt(partialend, 10) : GridFile.length - 1;
var chunksize = (end - start) + 1;
if(chunksize == 1){
start = 0;
partialend = false;
}
if(!partialend){
if(((GridFile.length-1) - start) < (buffer_size) ){
end = GridFile.length - 1;
}else{
end = start + (buffer_size);
}
chunksize = (end - start) + 1;
}
if(start == 0 && end == 2){
chunksize = 1;
}
res.writeHead(206, {
'Cache-Control': 'no-cache',
'Content-Range': 'bytes ' + start + '-' + end + '/' + GridFile.length,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/mp4',
});
GridFile.seek(start, function () {
// get GridFile stream
var stream = GridFile.stream(true);
var ended = false;
var bufferIdx = 0;
var bufferAvail = 0;
var range = (end - start) + 1;
var totalbyteswanted = (end - start) + 1;
var totalbyteswritten = 0;
// write to response
stream.on('data', function (buff) {
bufferAvail += buff.length;
//Ok check if we have enough to cover our range
if(bufferAvail < range) {
//Not enough bytes to satisfy our full range
if(bufferAvail > 0)
{
//Write full buffer
res.write(buff);
totalbyteswritten += buff.length;
range -= buff.length;
bufferIdx += buff.length;
bufferAvail -= buff.length;
}
}
else{
//Enough bytes to satisfy our full range!
if(bufferAvail > 0) {
var buffer = buff.slice(0,range);
res.write(buffer);
totalbyteswritten += buffer.length;
bufferIdx += range;
bufferAvail -= range;
}
}
if(totalbyteswritten >= totalbyteswanted) {
// totalbytes = 0;
GridFile.close();
res.end();
this.destroy();
}
});
});
}else{
// res.end(GridFile);
// stream back whole file
res.header('Cache-Control', 'no-cache');
res.header('Connection', 'keep-alive');
res.header("Accept-Ranges", "bytes");
res.header('Content-Type', 'video/mp4');
res.header('Content-Length', GridFile.length);
var stream = GridFile.stream(true).pipe(res);
}
};
P.S
The original answer is given by #Bragegs here - https://github.com/ParsePlatform/parse-server/issues/1440#issuecomment-212815625 .

jQuery datetimepicker: disable time

I am using the XDSoft jQuery datetimepicker in my app (Ruby on Rails 4 (just for information, not using bootstrap datetimepicker)).
I was wondering if there is a way to disable/deactivate a specific time at a specific date, for example disable only 17:00 on 12/17/2014?
disabledDates: ['...'] disables a specific date.
I tried disabledDateTimes and disabledTimes but they don't work.
Thanks.
Here is one example of how this can be done using the XDSoft DateTimePicker you are asking about.
I have a specificDates array which you can use to add dates you want to target.
I also have an hoursToTakeAway multi dimensional array which corresponds with the specificDates array where you can specify the hours to take away.
HTML
<input class="eventStartDate newEventStart eventEditDate startTime eventEditMetaEntry" id="from_date" name="from_date" placeholder="Start date and time" readonly="readonly" type="text" />
Javascript
var specificDates = ['24/12/2014','17/12/2014'];
var hoursToTakeAway = [[14,15],[17]];
$('#from_date').datetimepicker({
format:'d.m.Y H:i',
timepicker: true,
lang: 'en',
onGenerate:function(ct,$i){
var ind = specificDates.indexOf(ct.dateFormat('d/m/Y'));
$('.xdsoft_time_variant .xdsoft_time').show();
if(ind !== -1) {
$('.xdsoft_time_variant .xdsoft_time').each(function(index){
if(hoursToTakeAway[ind].indexOf(parseInt($(this).text())) !== -1) {
$(this).hide();
}
});
}
}
});
Example
Fiddle
Basically I am taking advantage of the onGenerate event which happens after each calendar has been rendered. Then I am checking to see if the date matches the specified day and if it does, we iterate through all the time elements and hide the ones specified for the specific date.
Updated Fiddle implementing disable.
Fiddle 2
This code is working for me:
var specificDates = ['24/12/2014','17/12/2014'];
var hoursToTakeAway = [[14,15],[17]];
$('#from_date').datetimepicker({
format:'d.m.Y H:i',
timepicker: true,
lang: 'en',
onGenerate:function(ct,$i){
var ind = specificDates.indexOf(ct.dateFormat('d/m/Y'));
$('.xdsoft_time_variant .xdsoft_time').show();
if(ind !== -1) {
$('.xdsoft_time_variant .xdsoft_time').each(function(index){
if(hoursToTakeAway[ind].indexOf(parseInt($(this).text())) !== -1) {
$(this).hide();
}
});
}
}
});
If someone still need solution, i write code to disable ranges of time in jquery-ui-datepicker.
First I need to init ranges, that will be disabled at current date:
dateObj1 = new Date(2016,6,22,0);
dateObj2 = new Date(2016,6,27,10);
diap1 = [dateObj1, dateObj2];
dateObj1 = new Date(2016,6,27,13);
dateObj2 = new Date(2016,6,27,14);
diap2 = [dateObj1, dateObj2];
dateObj1 = new Date(2016,6,27,20);
dateObj2 = new Date(2016,6,29,10);
diap3 = [dateObj1, dateObj2];
dateObj1 = new Date(2016,6,27,0);
dateObj2 = new Date(2016,6,27,13);
diap4 = [dateObj1, dateObj2];
dateObj1 = new Date(2016,7,02,4);
dateObj2 = new Date(2016,7,02,4,59);
diap5 = [dateObj1, dateObj2];
diapazons = [diap1,diap2,diap3,diap4,diap5];
Then I need function, to proceed this ranges, detect intersections and create ranges, that will be displayed:
function getAvailableTimes(restricts, curr_year, curr_month, cur_day)
{
day_diaps = [[new Date(curr_year,curr_month,cur_day,0), new Date(curr_year,curr_month,cur_day,23,59,59)]];
restricts.forEach(function(item, i, arr) {
day_diaps.forEach(function(day_diap, i_d, arr_d) {
//console.log('day = '+day_diap.toString());
if (day_diap[0] >= item[1])
{
//console.log(i+' раньше');
}
else if (day_diap[1] <= item[0])
{
//console.log(i+' позже');
}
else if (day_diap[0] >= item[0] && day_diap[1] <= item[1])
{
//console.log(i+' закрыт полностью');
arr_d.splice(i_d,1);
}
else if (day_diap[0] >= item[0] && day_diap[1] >= item[1])
{
day_diap[0] = item[1];
//console.log(i+' ранее перекрытие, начало смещено на '+ day_diap.toString());
}
else if (day_diap[0] <= item[0] && day_diap[1] <= item[1])
{
day_diap[1] = item[0];
//console.log(i+' позднее перекрытие, конец смещен на '+ day_diap.toString());
}
else if (day_diap[0] <= item[0] && day_diap[1] >= item[1])
{
new_diap = [item[1],day_diap[1]];
arr_d.push(new_diap);
day_diap[1] = item[0];
//console.log(i+' restrict полностью умещается в диапазон '+ day_diap.toString());
//console.log(i+' добавлен диапазон '+ new_diap.toString());
}
});
});
return day_diaps;
}
And code in of datetimepicker:
<input type="text" id="default_datetimepicker"/>
<script>
$.datetimepicker.setLocale('ru');
var dates_to_disable = ['30-07-2016','31-07-2016','04-08-2016'];
$('#default_datetimepicker').datetimepicker({
formatTime:'H:i',
lang: "ru",
defaultTime:"10:00",
formatDate:'d-m-Y',
todayButton: "true",
minDate:'01-01--1970', // yesterday is minimum date
disabledDates:dates_to_disable,
onGenerate:function(ct,i){
var dates = jQuery(this).find('.xdsoft_date ');
$.each(dates, function(index, value){
year = jQuery(value).attr('data-year');
month = jQuery(value).attr('data-month');
date = jQuery(value).attr('data-date');
diaps = getAvailableTimes(diapazons,year,month,date);
net_nihrena = true;
diaps.forEach(function(day_diap, i_d, arr_d) {
net_nihrena = false;
});
if (net_nihrena)
{
jQuery(value).addClass('xdsoft_disabled');
//jQuery(value).addClass('xdsoft_restricted');
}
});
cur_date = ct;
diaps = getAvailableTimes(diapazons,ct.getFullYear(),ct.getMonth(),ct.getDate());
var times = jQuery(this).find('.xdsoft_time ');
$.each(times, function(index){
var hour = $(this).attr('data-hour');
var minute = $(this).attr('data-minute');
cur_date.setHours(hour,minute,0);
net_takogo_vremeni = true;
diaps.forEach(function(day_diap, i_d, arr_d) {
if ((day_diap[0] < cur_date && day_diap[1] > cur_date) || hour==0)
{
net_takogo_vremeni = false;
}
});
if (net_takogo_vremeni)
{
$(this).addClass('xdsoft_disabled');
//$(this).addClass('xdsoft_restricted');
}
});
},
onSelectDate : function(ct) {
}
});
</script>

Twitter widget with api 1.1

I used the following widget that does not work anymore. It displays the latest tweet from chosen twitter accounts in turn. I have consumer key, secret and access token but don't know how to add it to make the widget work.
<script><!--
var feed = ["david_garrett", "50cent", "shemarmoore"];
var refresh = 20;
var direction = 0;
window.onload = function()
{
var scriptTag = document.createElement("script");
var location = (feed.constructor == Array) ? feed[Math.floor(Math.random() * feed.length)] : feed;
scriptTag.setAttribute("src", "https://api.twitter.com/1/statuses/user_timeline/" + location + ".json?callback=retrieveData&count=1&timestamp=no");
document.getElementsByTagName("body")[0].appendChild(scriptTag);
setTimeout("location.reload();", refresh * 1000);
}
function retrieveData(twitters)
{
var tweet = document.getElementById("u");
tweet.innerHTML = "<span><b>" + twitters[0].user.screen_name + "</b><br/>" + twitters[0].text + "</span>";
if (tweet.scrollHeight > tweet.clientHeight)
setTimeout(scrollWindow, 5000);
}
function scrollWindow()
{
var tweet = document.getElementById("u");
if (direction == 0)
tweet.scrollTop++;
else
tweet.scrollTop--;
if (tweet.scrollTop + tweet.clientHeight >= tweet.scrollHeight)
{
direction = 1;
setTimeout(scrollWindow, 5000);
}
else if (tweet.scrollTop <= 0)
{
direction = 0;
setTimeout(scrollWindow, 5000);
}
else
{
setTimeout(scrollWindow, 100);
}
}
//-->
</script>
it seems that twitter depracated v 1 completely. did you try setting 1.1 instead of 1 in this url?
https://api.twitter.com/1/statuses/user_timeline/
check this from twitter guys: https://dev.twitter.com/docs/api/1.1/overview
also this may be useful for you:
https://github.com/StanScates/Tweet.js-Mod

Resources