User:Natasa Siencnik/workshop1: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
[[Category:2011 P1.02]] | [[Category:2011 P1.02]] | ||
== Time for Revolution == | == Time for Revolution and Time for Rethinking what I am actually doing in this course == | ||
World Clock Installation<br /> | World Clock Installation<br /> | ||
<br /> | <br /> |
Revision as of 13:02, 29 March 2011
Time for Revolution and Time for Rethinking what I am actually doing in this course
World Clock Installation
1 - Ideas
2 - Description
Inspired by both the current political struggles in North Africa and the supposed lack of public participation in Western societies, the installation of 12 clocks is monitoring the political activity in a selection of countries. Conventional world clocks are typically found in loci such as hotel lobbies or stock market halls, representing stand-alone heterotopias, yet displaying their undeniable dependencies and power relations. But instead of progressing in time simultaneously, the incoming tweets about revolution are the engine for driving the clock hand. While time is running faster in some countries, others seem to be in a static mode, providing both stability and stagnancy. Presented simultaneous and equal in their physical manifestation, some clocks indicate it is time for change in an infinite loop.
3 - Technical Flowchart
4 - Script
Python : Script 2011-02-15
#!//usr/bin/python
import urllib2, json, sys
#from apikey import apikey
#api = twitter.Api(username=username, password=password)
url = 'http://search.twitter.com/search.json?q=%23revolution'
f = urllib2.urlopen(url)
data = json.load(f)
for r in data['results']:
# print r['created_at'] + r['from_user'] + ' : "' + r['text'] + '"'
sys.stdout.write r['created_at'] + r['from_user'] + ' : "' + r['text'] + '"'
Python : Script 2011-03-10
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os, urllib2, json, sys, codecs
enc = codecs.getencoder("ascii")
def twittersearch(tag):
url = enc(u'http://search.twitter.com/search.json?q=%%23%s' % tag, "xmlcharrefreplace")[0]
print("Query-URL: " + url)
f = urllib2.urlopen(url)
data = json.load(f)
out = []
for entry in data['results']:
d = {}
for key in ('created_at', 'id', 'text', 'iso_language_code') :
d[key] = entry[key]
out.append(d)
return out
list_of_languages = [
u"Rewolusie",
u"Revolucion",
#u"الثورة",
#u"Հեղափոխություն",
u"Inqilab",
u"Iraultza",
#u"Рэвалюцыі",
#u"Революция",
u"Revolució",
#u"革命",
u"Revolucija",
u"Revoluce",
u"Revolution",
u"Revolutie",
u"Revolutsioon",
u"Rebolusyon",
u"Vallankumous",
u"Révolution",
u"Revolución",
#u"რევოლუცია",
#u"Επανάσταση",
u"Revolisyon",
#u"מהפכה",
#u"क्रांति",
u"Forradalom",
u"Revolusi",
u"Réabhlóid",
u"Rivoluzione",
#u"革命",
#u"רעוואָלוציע",
#u"혁명",
u"Revolūcija",
u"Revoliucija",
#u"Револуција",
u"Rivoluzzjoni",
#u"انقلاب",
u"Rewolucji",
u"Revolução",
u"Revoluţie",
#u"Революции",
#u"Револуција",
u"Revolúcia",
u"Mapinduzi",
#u"การปฏิวัติ",
u"Devrim",
#u"Революції",
u"Cách mạng",
u"Chwyldro",
]
out = []
for tag in list_of_languages:
out.extend(twittersearch(tag))
ids = []
for entry in out:
if entry['id'] in ids:
print('non-unique id found\n')
else:
ids.append(entry['id'])
print("%(created_at)s - %(id)d : %(text)s\nIn %(iso_language_code)s" % entry)
sys.exit()
Python : Script 2011-03-24
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os, urllib2, json, sys, codecs, datetime
enc = codecs.getencoder("ascii")
def twittersearch(query):
url = enc(u'http://search.twitter.com/search.json?q=%s' % query, "xmlcharrefreplace")[0]
print("Query-URL: " + url)
f = urllib2.urlopen(url)
data = json.load(f)
out = []
for entry in data['results']:
d = {}
for key in ('created_at', 'id', 'text', 'iso_language_code') :
d[key] = entry[key]
out.append(d)
return out
list_of_queries = [
{"country":"Egypt","tags": ["revolution"]},
{"country":"Libya","tags": ["revolution"]}
]
out = {}
for qd in list_of_queries:
out[qd["country"]] = []
for tag in qd["tags"]:
query = u"%%23%s+%%23%s" % (tag, qd["country"])
out[qd["country"]].extend(twittersearch(query))
for (country, entries) in out.items():
ids = []
print(country)
for entry in entries:
if entry['id'] in ids:
print('non-unique id found\n')
else:
ids.append(entry['id'])
print("%(created_at)s - %(id)d : %(text)s\nIn %(iso_language_code)s" % entry)
sys.exit()
Python : Compare Date and Time
import datetime
In [4]: dt = datetime.datetime.strptime("24 Mar 2011 10:48:33", "%d %b %Y %H:%M:%S")
In [5]: dt
Out[5]: datetime.datetime(2011, 3, 24, 10, 48, 33)
In [6]: dt2 = datetime.datetime.strptime("24 Mar 2011 10:48:35", "%d %b %Y %H:%M:%S")
In [7]: dt2
Out[7]: datetime.datetime(2011, 3, 24, 10, 48, 35)
In [8]: dt2 > dt
Out[8]: True
In [9]: dt2 == dt
Out[9]: False
Python : Script 2011-03-28
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os, urllib2, json, sys, codecs, datetime, MySQLdb
enc = codecs.getencoder("ascii")
search = "revolution"
def twittersearch(query):
url = enc(u'http://search.twitter.com/search.json?q=%s' % query, "xmlcharrefreplace")[0]
print("Query-URL: " + url)
f = urllib2.urlopen(url)
data = json.load(f)
out = []
for entry in data['results']:
d = {}
for key in ('created_at', 'id', 'text', 'iso_language_code') :
d[key] = entry[key]
out.append(d)
return out
def getDateTime(timestring):
#return datetime suitable for mysql
return 0
conn = MySQLdb.connect (host = "localhost", user = "natasa", passwd = "********", db = "revolution")
list_of_queries = [
{"country":"Egypt","tags": [search]},
{"country":"Libya","tags": [search]}
]
out = {}
for qd in list_of_queries:
out[qd["country"]] = []
for tag in qd["tags"]:
query = u"%%23%s+%%23%s" % (tag, qd["country"])
out[qd["country"]].extend(twittersearch(query))
for (country, entries) in out.items():
ids = []
print(country)
for entry in entries:
if entry['id'] in ids:
print('non-unique id found\n')
else:
ids.append(entry['id'])
print("%(created_at)s - %(id)d : %(text)s\nIn %(iso_language_code)s" % entry)
time = 0;#getDateTime(created_at)
try:
query = "insert into tweets (tweet_id, tweet_time, tweet_search, tweet_text) values('%s', %d, '%s', '%s')" % (entry['id'], time, search, entry['text'])
print('query %s' % query)
cursor = conn.cursor ()
cursor.execute (query)
#update tags/tweet table
#update current time country
except ValueError:
print "tweet already in database"
conn.close()
sys.exit()
4 - Languages
Link: http://www.explore2india.com/worldcapital.htm
Link: http://en.wikipedia.org/wiki/List_of_countries_and_capitals_in_native_languages
Afriaans: Rewolusie
Albanian: Revolucion
Arabic: الثورة
Armenian: Հեղափոխություն
Azerbaijjani: Inqilab
Basque: Iraultza
Belarusian: Рэвалюцыі
Bulgarian: Революция
Catalan: Revolució
Chinese: 革命
Croatian: Revolucija
Czech: Revoluce
Danish: Revolution
Dutch: Revolutie
English: Revolution
Estonian: Revolutsioon
Filipino: Rebolusyon
Finnish: Vallankumous
French: Révolution
Galician: Revolución
Georgian: რევოლუცია
German: Revolution
GreeK: Επανάσταση
Haitian: Revolisyon
Hebrew: מהפכה
Hindi: क्रांति
Hungarian: Forradalom
Icelanding: Revolution
Indonasian: Revolusi
Irish: Réabhlóid
Italian: Rivoluzione
Japanese: 革命
Jiddish: רעוואָלוציע
Korean: 혁명
Latvian: Revolūcija
Lithuanian: Revoliucija
Macedonian: Револуција
Malay: Revolusi
Maltese: Rivoluzzjoni
Norvegian: Revolution
Persian: انقلاب
Polish: Rewolucji
Portuguese: Revolução
Romanian: Revoluţie
Russian: Революции
Serbian: Револуција
Slovak: Revolúcia
Slovenian: Revolucija
Spanish: Revolución
Swahili: Mapinduzi
Swedish: Revolution
Tagalog: Rebolusyon
Thai: การปฏิวัติ
Turkish: Devrim
Ukrainian: Революції
Urdu: انقلاب
Vietnamese: Cách mạng
Welsh: Chwyldro
5 - List of Countries
LY - Libya - Tripoli
EG - Egypt - Cairo
IQ - Iraq - Baghdad
RU - Russia - Moskow
JP - Japan - Tokyo
IN - India - New Delhi
CN - China - Beijing
KP - North Korea - Pyongyang
IL - Israel - Jerusalem
US - United States - New York
UK - United Kingdom - London
NL - Netherlands - Amsterdam
5 - Outcome
| 52403985604296705 | 0000-00-00 00:00:00 | revolution
Text #Freedom #Revolution Freedom Revolution Freedom Revolution Freedom Revolution Freedom Revolution #Syria #Egypt #China #Iran #NorthKorea
6 - Tasks
timestamp that SQL understands
create SQL table "countries"
create SQL table "tweets/countries"
analyse text > look for query > write in table "tweets/country" > update time in table "country"
7 - Questions
How can I implement a time stamp and check for doubles?
What kind of program do I need to run this on a server?
Thanks to Stock and Evo for the technical super-support and Stefan Weber for his helpful input and feedback. :)