|
1 import sqlite3 |
|
2 import twython |
|
3 |
|
4 def get_option(): |
|
5 |
|
6 parser = OptionParser() |
|
7 |
|
8 parser.add_option("-l", "--log", dest="logfile", |
|
9 help="log to file", metavar="LOG", default="stderr") |
|
10 parser.add_option("-v", dest="verbose", action="count", |
|
11 help="verbose", metavar="VERBOSE", default=0) |
|
12 parser.add_option("-q", dest="quiet", action="count", |
|
13 help="quiet", metavar="QUIET", default=0) |
|
14 parser.add_option("-r", "--request", dest="request", |
|
15 help="twitter request", metavar="REQUEST", default=0) |
|
16 #add request token |
|
17 #add |
|
18 |
|
19 return parser.parse_args() |
|
20 |
|
21 if __name__ == "__main__": |
|
22 |
|
23 twitter = twython.Twython() |
|
24 conn = sqlite3.connect('enmi2010_twitter_rest.db') |
|
25 try: |
|
26 conn.row_factory = sqlite3.Row |
|
27 curs = conn.cursor() |
|
28 curs.execute("create table if not exists tweet_tweet (json);") |
|
29 conn.commit() |
|
30 |
|
31 results = twitter.searchTwitter(q="#enmi", rpp="50") |
|
32 for tweet in results["results"]: |
|
33 print tweet |
|
34 curs.execute("insert into tweet_tweet (json) values (:json);", {"json":unicode(tweet)}) |
|
35 conn.commit() |
|
36 finally: |
|
37 conn.close() |
|
38 |
|
39 |