def __init_tweet(self, game): content = self.__compose_tweet(game) is_doubleheader = self.__checkIfDoubleHeader(self._date) game_num = game['@game_nbr'] game_id = str(game['@id']) game_start = dateutil.parser.parse(game['@start']).replace(tzinfo = dateutil.tz.tzutc()) # new_time = game_start.replace(tzinfo = dateutil.tz.tzutc()) time_tweeted = datetime.datetime.now(timezone('America/Chicago'))-datetime.timedelta(hours=5) if self._environment == 'production': db = MyDB() db.db_cur.execute("INSERT INTO tweets (content, is_doubleheader, game_num, game_id, game_start, time_tweeted) VALUES (%s, %s, %s, %s, %s, %s)", (content, is_doubleheader, game_num, game_id,game_start, time_tweeted)) db.finish_query() twitter = self.__twitter_connect() twitter.PostUpdate(content)
def __did_tweet(self, day, game): db = MyDB() db.db_cur.execute("SELECT * FROM tweets;") tweets_list = db.db_cur.fetchall() db.finish_query() # if checkIfDoubleHeader(getXMLData(createURLFromDate(day))): tweeted = False if self.__didCardinalsLose(game): for entry in tweets_list: if entry['game_id'] == game['@id']: # if self.__parse_date(entry['game_start']) == self.__parse_date(day): tweeted = True if tweeted: print "there was already a tweet for this game" else: print "No tweet yet" return tweeted