| author | Raphael Velt <raph.velt@gmail.com> |
| Wed, 25 Jul 2012 18:03:07 +0200 | |
| changeset 668 | eb7e39c732c6 |
| parent 529 | 99215db3da25 |
| child 693 | 2ef837069108 |
| permissions | -rw-r--r-- |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
1 |
from iri_tweet.models import setup_database, Message, UserMessage, User |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
2 |
from iri_tweet.utils import (get_oauth_token, get_user_query, set_logging_options, |
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
3 |
set_logging, parse_date, get_logger) |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
4 |
from optparse import OptionParser #@UnresolvedImport |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
5 |
from sqlalchemy import BigInteger |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
6 |
from sqlalchemy.schema import Table, Column |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
7 |
from sqlalchemy.sql import and_ |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
8 |
import datetime |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
9 |
import re |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
10 |
import sys |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
11 |
import twitter |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
12 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
13 |
APPLICATION_NAME = "Tweet recorder user" |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
14 |
CONSUMER_KEY = "Vdr5ZcsjI1G3esTPI8yDg" |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
15 |
CONSUMER_SECRET = "LMhNrY99R6a7E0YbZZkRFpUZpX5EfB1qATbDk1sIVLs" |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
16 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
17 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
18 |
def get_options(): |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
19 |
parser = OptionParser() |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
20 |
parser.add_option("-d", "--database", dest="database", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
21 |
help="Input database", metavar="DATABASE") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
22 |
parser.add_option("-s", "--start-date", dest="start_date", |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
23 |
help="start date", metavar="START_DATE", default=None) |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
24 |
parser.add_option("-e", "--end-date", dest="end_date", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
25 |
help="end date", metavar="END_DATE") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
26 |
parser.add_option("-H", "--hashtag", dest="hashtag", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
27 |
help="Hashtag", metavar="HASHTAG", default=[], action="append") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
28 |
parser.add_option("-x", "--exclude", dest="exclude", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
29 |
help="file containing the id to exclude", metavar="EXCLUDE") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
30 |
parser.add_option("-D", "--duration", dest="duration", type="int", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
31 |
help="Duration", metavar="DURATION", default=None) |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
32 |
parser.add_option("-m", "--message", dest="message", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
33 |
help="tweet", metavar="MESSAGE", default="") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
34 |
parser.add_option("-u", "--user", dest="user", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
35 |
help="user", metavar="USER") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
36 |
parser.add_option("-w", "--password", dest="password", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
37 |
help="password", metavar="PASSWORD") |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
38 |
parser.add_option("-t", dest="token_filename", metavar="TOKEN_FILENAME", default=".oauth_token", |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
39 |
help="Token file name") |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
40 |
parser.add_option("-S", dest="simulate", metavar="SIMULATE", default=False, action="store_true", help="Simulate call to twitter. Do not change the database") |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
41 |
parser.add_option("-f", dest="force", metavar="FORCE", default=False, action="store_true", help="force sending message to all user even if it has already been sent") |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
42 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
43 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
44 |
set_logging_options(parser) |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
45 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
46 |
return parser.parse_args() |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
47 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
48 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
49 |
if __name__ == "__main__": |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
50 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
51 |
(options, args) = get_options() |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
52 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
53 |
set_logging(options) |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
54 |
|
|
286
6ac68295defe
remove Jane McGonigal (publication right problems) + correct synclive for limesurvey + small correction for tweet_user
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
255
diff
changeset
|
55 |
get_logger().debug("OPTIONS : " + repr(options)) #@UndefinedVariable |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
56 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
57 |
if not options.message or len(options.message) == 0: |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
58 |
get_logger().warning("No message exiting") |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
59 |
sys.exit() |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
60 |
|
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
61 |
conn_str = options.database.strip() |
|
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
62 |
if not re.match("^\w+://.+", conn_str): |
|
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
63 |
conn_str = 'sqlite:///' + conn_str |
|
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
64 |
|
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
65 |
engine, metadata, Session = setup_database(conn_str, echo=((options.verbose-options.quiet)>0), create_all = False) |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
66 |
|
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
67 |
conn = None |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
68 |
try : |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
69 |
conn = engine.connect() |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
70 |
session = None |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
71 |
try: |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
72 |
session = Session(bind=conn, autoflush=True, autocommit=True) |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
73 |
tweet_exclude_table = Table("tweet_exclude", metadata, Column('id', BigInteger, primary_key=True), prefixes=['TEMPORARY']) |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
74 |
metadata.create_all(bind=conn,tables=[tweet_exclude_table]) |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
75 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
76 |
start_date_str = options.start_date |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
77 |
end_date_str = options.end_date |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
78 |
duration = options.duration |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
79 |
hashtags = options.hashtag |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
80 |
|
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
81 |
start_date = None |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
82 |
if start_date_str: |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
83 |
start_date = parse_date(start_date_str) |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
84 |
|
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
85 |
end_date = None |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
86 |
if end_date_str: |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
87 |
end_date = parse_date(end_date_str) |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
88 |
elif start_date and duration: |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
89 |
end_date = start_date + datetime.timedelta(seconds=duration) |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
90 |
|
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
91 |
base_message = options.message.decode(sys.getfilesystemencoding()) |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
92 |
#get or create message |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
93 |
message_obj = session.query(Message).filter(Message.text == base_message).first() |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
94 |
if not message_obj : |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
95 |
message_obj = Message(text=base_message) |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
96 |
session.add(message_obj) |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
97 |
session.flush() |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
98 |
|
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
99 |
query = get_user_query(session, start_date, end_date, hashtags, tweet_exclude_table) |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
100 |
|
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
101 |
if not options.force: |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
102 |
query = query.outerjoin(UserMessage, and_(User.id == UserMessage.user_id, UserMessage.message_id == message_obj.id)).filter(UserMessage.message_id == None) |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
103 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
104 |
query_res = query.all() |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
105 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
106 |
acess_token_key, access_token_secret = get_oauth_token(options.token_filename, application_name=APPLICATION_NAME, consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET) |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
107 |
t = twitter.Twitter(auth=twitter.OAuth(acess_token_key, access_token_secret, CONSUMER_KEY, CONSUMER_SECRET)) |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
108 |
|
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
109 |
for user in query_res: |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
110 |
screen_name = user.screen_name |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
111 |
|
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
112 |
message = u"@%s: %s" % (screen_name, base_message) |
|
286
6ac68295defe
remove Jane McGonigal (publication right problems) + correct synclive for limesurvey + small correction for tweet_user
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
255
diff
changeset
|
113 |
get_logger().debug("new status : " + message) #@UndefinedVariable |
|
98
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
114 |
if not options.simulate: |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
115 |
t.statuses.update(status=message) |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
116 |
user_message = UserMessage(user_id=user.id, message_id=message_obj.id) |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
117 |
session.add(user_message) |
|
6e8930a1b8f7
add tools to track tweeter messaging
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
118 |
session.flush() |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
119 |
finally: |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
120 |
# if message created and simulate, do not |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
121 |
if session: |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
122 |
session.close() |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
123 |
finally: |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
124 |
if conn: |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
286
diff
changeset
|
125 |
conn.close() |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
126 |