def load_and_classify_job(coin): localtz = pytz.timezone('US/Pacific') todate = datetime.now(localtz) try: last_tweet = find_last_tweet(coin) from_date = last_tweet[0]['created_at'] print(from_date) except Exception: from_date = (datetime.now(localtz) + timedelta(days=-30)).isoformat() print("Loading tweets from {} to {}".format( from_date, (todate + timedelta(days=1)).isoformat())) load_tweets(from_date, (todate + timedelta(days=1)).isoformat(), coin) #recover hours = (todate - parse(from_date)).total_seconds() / 3600 for i in range(0, int(hours)): from_range = to_date(from_date) + timedelta(hours=i) to_range = to_date(from_date) + timedelta(hours=i + 1) classify_new_tweets(coin, from_range.isoformat(), to_range.isoformat(), from_range.isoformat()) #last classification todate_new = datetime.now(localtz) fromdate_new = datetime.now(localtz) - timedelta(hours=-1) classify_new_tweets(coin, fromdate_new.isoformat(), todate_new.isoformat(), fromdate_new.isoformat()) build_influencers(coin)
def __init__(self, params_dict): self.twitter_id = params_dict.get("id") self.text = params_dict.get("text") self.sentiment = None self.sentiment_score = None self.created_at = to_date(params_dict.get("created_at")) self.author = Author(params_dict.get("user"))
def __init__(self, params_dict): self.twitter_id = params_dict.get("id") self.name = params_dict.get("name") self.followers_count = params_dict.get("followers_count") self.friends_count = params_dict.get("friends_count") self.favourites_count = params_dict.get("favourites_count") self.created_at = to_date(params_dict.get("created_at")) self.verified = params_dict.get("verified") self.location = params_dict.get("location") self.url = params_dict.get("url") self.retweet_rate = None self.like_rate = None self.reply_rate = None
def find_classification(coin_code, start_date, end_date): collection = db[coin_code.lower()] classifications = list( collection.find( {'classification_date': { '$gte': start_date, '$lt': end_date }})) for classification in classifications: classification['_id'] = str(classification['_id']) classification['classification_date'] = to_date( to_local_timezone(classification['classification_date'])) return classifications
def get_coin_price(coin_code, currency, time=None): return cryptocompare.get_historical_price(coin_code, currency, time) def get_coin_list(): coin_dict = cryptocompare.get_coin_list() coins = [] for key, coin_data in coin_dict.items(): id = int(coin_data[coin_property.ID]) code = coin_data[coin_property.NAME] name = coin_data[coin_property.FULL_NAME] sortOrder = int(coin_data[coin_property.SORT_ORDER]) coin = Coin(id, code.lower(), name.lower(), sortOrder) coins.append(coin) sorted_coins = sorted(coins, key=lambda x: x.sortOrder) return sorted_coins if __name__ == "__main__": import time date_str = "2018-05-17T18:20:00.448083-07:00" date_gmt = to_date(to_gmt(date_str)) timestamp = time.mktime(date_gmt.timetuple()) print(timestamp) #price = get_coin_price("ZIL", "USD", date_gmt) #print(price['ZIL']['USD'])