def create_cut_table(self): self.first_date = CandleTable.get_first_date(self.candle_table_name) self.last_date = CandleTable.get_last_date(self.candle_table_name) self.cut_trend_table_name = self.get_trend_table_name() if DBManager.exists_table(self.cut_trend_table_name): DBManager.drop_table(self.cut_trend_table_name) tt = TrendTable(self.cut_trend_table_name) tt.save() candles = CandleTable.get_candle_array(self.candle_table_name) for c in candles: date = c.date hits = TrendTable.get_most_recent_hits(self.trend_table_name, date) trend = Trend(dbm, self.cut_trend_table_name, date, hits) trend.save() ##cursor = TrendTable.get_section(self.trend_table_name, self.first_date, self.last_date) ##trend_tuples = cursor.fetchall() ##for t in trend_tuples: ##date = t[0] ##hits = t[1] ##trend = Trend(dbm, self.cut_trend_table_name, date, hits) ##trend.save() ##dbm.save_and_close() return tt
def insert(self): rows = self.data["table"]["rows"] for r in rows: try: date_string = r["c"][0]["v"] print(date_string) date = date_to_timestamp(date_string) hits = r["c"][1]["f"] t = Trend(self.table_name, date, hits) t.save() except: print("reached the end")
# -*- coding: utf-8 -*- #Alcamena 10 tendencias en la base de datos.# from twython import Twython, TwythonError from trend import Trend from mongoengine import connect connect('twitter') twitter = Twython("iDGDpOTDVj7mwGDD4pkAMw", "rKOrMHCvsP98lISbyXnHPaR7HFWj44PsAa4Yy7cCQvE", "222814276-KsT3JiNkqUCALLKrfFegVenxi229thKKxjkM2Zpr", "soCtSgfJyzuAEhXvN466LZao7Xc5RcenjFbTmd1TA") try: search_results = twitter.get_place_trends(id = 23424787) for trend in search_results[0].get('trends', []): t = Trend(trend) t.save() except TwythonError as e: print e