def get_tweet_count_today(self, region, date=datetime.datetime.today()): db = CloudantDatabase(self.client, self.get_region(region), partitioned=True) counts = 0 for re in db.get_partitioned_view_result(date, '_design/tweet_count', 'tweet_count'): counts += re['value'] return {'count': counts}
def get_corona(self, region, date_begin, date_end): db = CloudantDatabase(self.client, self.get_region(region), partitioned=True) days = get_days(date_begin, date_end) counts = 0 for day in days: for re in db.get_partitioned_view_result( day, '_design/coronavirus_related', 'coronavirus_related'): counts += re['value'] return {'count': counts}
def get_sentiment(self, region, date_begin, date_end): db = CloudantDatabase(self.client, self.get_region(region), partitioned=True) days = get_days(date_begin, date_end) counts = {'negative': 0, 'neutral': 0, 'positive': 0} for day in days: for re in db.get_partitioned_view_result(day, '_design/sentiment_count', 'sentiment_count', group_level=1): counts[re['key']] += re['value'] return counts
def get_hashtag_overview(self, region, date_begin, date_end, top): db = CloudantDatabase(self.client, self.get_region(region), partitioned=True) days = get_days(date_begin, date_end) results = {} for day in days: tmp_re = db.get_partitioned_view_result(day, '_design/hashtag_count', 'hashtag_count', group_level=1, limit=1000) for re in tmp_re[:]: results[re['key'].lower()] = results.get(re['key'].lower(), 0) + re['value'] if top: return sorted(results.items(), key=lambda item: item[1], reverse=True)[:top] else: return sorted(results.items(), key=lambda item: item[1], reverse=True)