How to filter tweets via the since/until parameters in Twitter4J queries? - twitter

I m listening twitter streams by coordinate using twitter4j without any input keyword, as i know twitter api just gives tweets of last 7 days. My code was working funny and i had an network problem and i could not get streams of 2 days ago. i need to get tweets of 22.04.2018 and 23.04.2018. I need to use until parameter to get these tweets but i could not see any sample of using until parameter without any input query. The following is my code statement when i listen for streams in given coordinates, how can i add until parameter to get past 2 days streams.
double latitude1 = 36.000000;
double longitude1 = 26.000000;
double latitude2 = 42.000000;
double longitude2 = 45.000000;
double[][] latlong = {{longitude1, latitude1}, {longitude2, latitude2}};
twitterStream.addListener(listener);
FilterQuery fq = new FilterQuery();
fq.locations(latlong);
twitterStream.filter(fq);
So the question is how can i use FilterQuery with until,
i tried something like as follows ;
MyConnectionBuilder myConnection = new MyConnectionBuilder();
Twitter twitter = new
TwitterFactory(myConnection.configuration.build()).getInstance();
double latitude1 = 42.000000;
double longitude1 = 45.000000;
Query query = new Query();
GeoLocation obj = new GeoLocation(latitude1, longitude1);
query.setGeoCode(obj, 2000, Unit.valueOf("km"));
query.setSince("20180421");
query.setUntil("20180422");
query.setLang("tr");
QueryResult result = twitter.search(query);
for (Status status : result.getTweets()) {
System.out.println("#" + status.getUser().getScreenName() + ":" + status.getText());
}
but nothing comes from result query, what can be wrong with these code statements ?

The official JavaDoc of Twitter4J's Query class tells us for setSince:
If specified, returns tweets with since the given date.
Date should be formatted as YYYY-MM-DD
So have to set a date in the String format YYYY-MM-DD, e.g., "2018-04-21". Note well, that dashes are used here which you did not provide in your original code snippet.
Analogously, you have to apply this date pattern style to setUntil:
If specified, returns tweets with generated before the given date.
Date should be formatted as YYYY-MM-DD
Hope this helps.

Related

Time to word converter

I was wondering if I could make an app in which time is display in words instead of conventional numbers. Do you think that there is any package for dart to convert time or numbers to words?
For example
1:30 AM will be One : Thirty AM
Thanks for reading this question. Have a wonderful day.
You can use any of available package to convert from number to words example
package: https://pub.dev/packages/number_to_words
import 'package:number_to_words/number_to_words.dart';
main(){
String input = '1:30 AM';
var s1 = input.split(':');
var s2 = s1[1].split(' ');
String hour = s1[0];
String minute = s2[0];
String hourWord = NumberToWord().convert('en-in',int.parse(hour));
String minuteWord = NumberToWord().convert('en-in',int.parse(minute));
print('$hourWord:$minuteWork ${s2[1]}');
}

Twitter text retrieval with new 280 character system

Using Google Scripts, I have a program that retrieves the text from one account's tweets and uses it for various other things. It's been running for over a year with minimal issues, but now the tweets are being adjusted to 280 characters and I can't retrieve the second half of the tweet. I have:
function refreshing_v2() {
var service = getTwitterService();
if (service.hasAccess()) {
var url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=(redacted)&count=1&include_rts=0&exclude_replies=1';
var response = service.fetch(url);
var tweets = JSON.parse(response.getContentText());
for (var i = 0; i < tweets.length; i++) {
//Parse the tweet
var latest = new String(tweets[i].text);
var maxi_id = tweets[i].id;
var startpos = latest.indexOf("1: ");
etc, etc, continues doing stuff with what it's found.
This allows me to get the FIRST half of the text. What's retrieved looks something like "[Content of first half]...(link to tweet)"
How do I get the full text?
You need to add tweet_mode=extended to get the full text in the response. You may need to check the entities you receive to see if it is what you are expecting.
Documentation link - https://developer.twitter.com/en/docs/tweets/tweet-updates
Additionally, you will need to use full_text rather than just text
So:
//Parse the tweet
var latest = new String(tweets[i].full_text);
See the sample tweet at https://github.com/twitterdev/tweet-updates/blob/master/samples/initial/compatibilityplus_extended_13997.json

Associate specific string to a number in google sheets

I am using a google forms to collect responses which I will then use to score people. Unfortunately some of those responses only make sense in a non numeric form, here is an example:
Q: What is your most common mode of transportation?
Car
Carpool
Public transportation
Bike
Walk
I want to be able to have google sheets automatically convert those string responses into a number, as in Car will be 20, carpool 15 and so on so that I can "grade" them and give them a score. Can this be done through google forms? Or maybe some sort of dictionary function?
Thank you!
Another method, requiring no coding, would be to make a worksheet with the encoding of the options and then use VLOOKUP to translate them.
Yep, this can be done through Google Forms. Have a look at https://developers.google.com/apps-script/reference/forms/duration-item#setPoints(Integer)
Using their code, you could go something like
var formResponses = FormApp.getActiveForm().getResponses();
// Go through each form response
for (var i = 0; i < formResponses.length; i++) {
var response = formResponses[i];
var items = FormApp.getActiveForm().getItems();
// Assume it's the first item
var item = items[0];
var itemResponse = response.getGradableResponseForItem(item);
if (itemResponse != null && itemResponse.getResponse() == 'Car') {
var points = item.asMultipleChoiceItem().getPoints();
itemResponse.setScore(points * 20);
// This saves the grade, but does not submit to Forms yet.
response.withItemGrade(itemResponse);
}
}
// Grades are actually submitted to Forms here.
FormApp.getActiveForm().submitGrades(formResponses);

How to parse multiple nodes of html using HtmlAgilityPack?

I'd appreciate if someone could help! I'm trying to parse the following page of Groupon website http://www.groupon.com/browse/chicago?category=activities-and-nightlife
var webGet = new HtmlWeb();
var deal1 = webGet.Load("http://www.groupon.com/browse/chicago?category=activities-and-nightlife");
I want to get the whole block of each Deal(i.e. offer for discount)
HtmlNodeCollection content_block = deal1.DocumentNode.SelectNodes("//div[#class = 'deal-list-tile grid_5_third']");
Then out of each block i want to get title, company name, location and price.
foreach(HtmlNode node in content_block)
{
string title2 = node.SelectSingleNode("//div[#class = 'deal-title js-permalink']").InnerText;
string country2 = node.SelectSingleNode("//p[#class = 'merchant-name']").InnerText;
string location2 = node.SelectSingleNode("//p[#class = 'location']").InnerText;
string price2 = node.SelectSingleNode("//div[#class = 'price']/span").InnerText;
}
Here i get confused, i need to write all the information about deals into
DbSet<Deal> Deals , but even if i try to display the content as ViewBag.Message = title + country + location + price; i get System.NullReferenceException: Object reference not set to an instance of an object in the line with content_block.
What am i doing wrong =(
Thanks in advance!
The problem appears to be that the selectnodes returns nothing or null when no nodes are found instead of an empty collection. so this means you should probably wrap if (content_block != null) { around your code block above.

Format decimal values on a BlackBerry

I am displaying a double to the user, but it is printed as 1.00000000001
However, I need only two digits after the decimal point.
There's a class called Formatter that can do the trick. Here's a code snippet:
double value = 1.24790000001;
Formatter formatter = new Formatter();
String formatted = formatter.formatNumber(value, 2);
And, here's a link to the JavaDoc: javax.microedition.global.Formatter
Have you looked at String.format e.g.
String x = String.format("%.2f", number);
http://download.oracle.com/javase/6/docs/api/java/lang/String.html

Resources