Erinevus lehekülje "ITI0011:Twitter homework" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
(Uus lehekülg: 'Back to course web page This is English version of second homework. Estonian version is here: ITI0011:Säuts. == General == <div style="color: red;">Some detai...')
 
60. rida: 60. rida:
 
</pre>
 
</pre>
  
 +
In the results you will see several places with the name Tallinn (or the name includes Tallinn). For the given homework, the first result is what you need to look for. So, you have to read first "place" element. For the Twitter query you need location (latitude and longitude) and radius. From the location search result, you should look for attributes "lat" and "lon" to be used as the center of the Twitter search. For the radius, use "boungindbox" attribute, which gives you the bounding box around the location. In the given example, you should look for lat="59.4372155", lon="24.7453688", boundingbox="59.351806640625,59.5915794372559,24.5501689910889,24.9262847900391".
  
<!--
+
For the radius, you could just find the distance between latitude and longitude. Beware that in different locations on Earth 0.1 longitude difference has difference distance. For this homework, the radius calculated should not be very accurate. But it still should vary depending on the size of the city (New York > .. > Tallinn > Haapsalu). Don't waste too much time for radius calculation, this won't give you any extra points, if you calculate it with 1m accuracy.
 
 
Tulemuseks saate mitu erinevat kohta, mille nimi on Tallinn (või nimes sisaldub selline sõna). Kõige esimene vaste meie programmi jaoks sobib. Seega loete välja esimese "place" elemendi. Kuna Twitteri päringu jaoks on meil vaja koordinaati ning raadiust (kui suure ala pealt tulemusi otsitakse), siis huvitavad meid atribuudid "lat" ja "lon" (latitude ja longitude), mis määravad ära keskpunkti, ning atribuut "boundingbox", mis näitab antud asukoha ümbritseva ala piirjooni. Antud näite näite puhul lat="59.4372155", lon="24.7453688", boundingbox="59.351806640625,59.5915794372559,24.5501689910889,24.9262847900391".
 
 
 
Twitteri päringus otsitav piirkond on märgitud keskpunkti ning raadiusega. Keskpunktiks võib kasutada otse eelnevalt saadud "lat" ja "lon" väärtusi. Raadiuse leidmiseks võib kasutada "boundingbox" väärtust. Kuna raadius peab olema esitatud näiteks kilomeetrites, siis tuleks boundingbox argumentide järgi leida mõistlik raadius. Tähelepanu, erinevas maakera piirkonnas on näiteks latitude 0.1 ühikuline erinevus oluliselt erineva pikkusega. Antud ülesande jaoks ei pea te arvutama väga täpse raadiuse, mis piiratud alasse sisse jääb. Piisab, kui te suurusjärgu panete paika. Siin ülesande kirjelduses konkreetset valemit või näidet toodud ei ole - selle võrra tulevad loodetavasti esitatud kodused ülesanded võimalikult erinevad. Väga täpseks ja põhjalikuks ei tasu ka minna - boonuspunkte selle arvutuse eest üldjuhul ei saa.
 
  
Seega teil on oluline, et oskate vajalikud andmed välja lugeda ning need teisendada keskpunktiks ja raadiuseks.
+
In short, you need to make a query, read the response, and translate the response into center coordinates and a radius.
  
Märkus. Põhiosa lahendamiseks sobib ka see, kui kasutate mõnda muud API-t (näiteks Google Maps'i oma).
+
Note: You could use some other service to get city coordinates (for example Google Maps API).
  
 
=== Twitteri API ===
 
=== Twitteri API ===
  
 +
<!--
 
Twitteri API (https://dev.twitter.com/docs/api/1.1) võimaldab programmiga teha automaatseid päringuid sotsiaalvõrgustiku Twitter andmetest. Antud ülesande lahendamiseks ei pea te olema aktiivne Twitteri kasutaja.
 
Twitteri API (https://dev.twitter.com/docs/api/1.1) võimaldab programmiga teha automaatseid päringuid sotsiaalvõrgustiku Twitter andmetest. Antud ülesande lahendamiseks ei pea te olema aktiivne Twitteri kasutaja.
  

Redaktsioon: 26. september 2014, kell 02:54

Back to course web page

This is English version of second homework. Estonian version is here: ITI0011:Säuts.

General

Some details may still change - overall requirements are fixed

Deadline: 21. or 23. October (depending on your practice time)
Defending your homework one week before (or earlier) will give you +1 point.

The goal of the homework is to create an interactive program which gets public tweets from Twitter API. The main part gives you 5 points. Additional functionality will give you additional points. Up to 11 points this time.

The required functionality:

  • Program accepts command-line arguments and everything is controllable from the arguments (example: java Twitter -location Tallinn -count 40 -sort date desc)
  • If the program is executed without arguments, an interactive command-line is executed, where the use can write commands ("> query Tallinn" or "> sort date desc")
  • Program has a proper manual (if some commands are written wrong or some parameters are missing, the help text should be shown; also "java Twitter --help" for example should print out the manual).
  • The program accepts a location and find last public tweets for that location and outputs those.
  • The number of tweets requested can be changed.
  • Downloaded tweets can be sorted and searched for.

Requirements are written in detail below. The list above is a general overview of the program (there are some more functionality features which need to be implemented).

Main part - 5p

The program makes a request to Twitter API to search public tweets. Last public tweets are downloaded in the location specified by the user from command line. The tweets are presented to the user.

Note that from Twitter API you just download the tweets (nothing special needs to be done to get the latest tweets - this is the default behavior). Also, when present tweets to the user, just print them out in the same order you receive.

Required functionality:

  • Read the location from command line (ex. "Tallinn")
  • For the location, find the geographical coordinates (latitude and longitude) using OpenStreetMap API
  • Use the bounding box information to calculate appropriate radius.
  • Send the coordinates and the radius to Twitter API
  • Read out the response from Twitter API into objects.
  • Print out the tweets.


Location coordinates

You can use OpenStreetMap community tool named Nominatim (Nominatim wiki). Given a location name it will return information about this location (coordinates, bounding box and other stuff).

Example request: http://nominatim.openstreetmap.org/search?q=Tallinn&format=xml

You will get a response (only partially shown):

<searchresults timestamp="Sat, 13 Sep 14 21:47:21 +0000" 
attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" 
querystring="Tallinn" polygon="false" 
exclude_place_ids="98174326,11438224,6000303521,6919504,6893196,86869124,15103978,5983246058" 
more_url="http://nominatim.openstreetmap.org/search?format=xml&
exclude_place_ids=98174326,11438224,6000303521,6919504,6893196,86869124,15103978,5983246058&accept-language=en-
US,en;q=0.5&q=Tallinn">
<place place_id="98174326" osm_type="relation" osm_id="2164745" place_rank="16" 
boundingbox="59.351806640625,59.5915794372559,24.5501689910889,24.9262847900391" lat="59.4372155" 
lon="24.7453688" display_name="Tallinn, Harju maakond, Estonia" class="place" type="city" 
importance="0.7819722223575" icon="http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"/>
...
</searchresults>

In the results you will see several places with the name Tallinn (or the name includes Tallinn). For the given homework, the first result is what you need to look for. So, you have to read first "place" element. For the Twitter query you need location (latitude and longitude) and radius. From the location search result, you should look for attributes "lat" and "lon" to be used as the center of the Twitter search. For the radius, use "boungindbox" attribute, which gives you the bounding box around the location. In the given example, you should look for lat="59.4372155", lon="24.7453688", boundingbox="59.351806640625,59.5915794372559,24.5501689910889,24.9262847900391".

For the radius, you could just find the distance between latitude and longitude. Beware that in different locations on Earth 0.1 longitude difference has difference distance. For this homework, the radius calculated should not be very accurate. But it still should vary depending on the size of the city (New York > .. > Tallinn > Haapsalu). Don't waste too much time for radius calculation, this won't give you any extra points, if you calculate it with 1m accuracy.

In short, you need to make a query, read the response, and translate the response into center coordinates and a radius.

Note: You could use some other service to get city coordinates (for example Google Maps API).

Twitteri API