-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_generator.py
36 lines (29 loc) · 989 Bytes
/
tweet_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import random
import datetime
from tweet_db import tweet_list
class TweetGenerator(object):
def __init__(self):
self.tweets = tweet_list.copy()
random.shuffle(self.tweets)
def _get_tweet(self, tag):
lentweets = len(self.tweets)
proposed_tweet = self.tweets[random.randint(0, lentweets - 1)]
if tag in proposed_tweet['time_tags'] or 'any' in proposed_tweet['time_tags']:
return proposed_tweet['tweet_templ']
return self._get_tweet(tag)
def _get_tag(self):
now = datetime.datetime.now()
hour = now.hour
if hour in range(0, 6):
return 'night'
elif hour in range(6, 11):
return 'morning'
elif hour in range(11, 14):
return 'lunch'
elif hour in range(14, 18):
return 'afternoon'
else:
return 'evening'
def get_tweet(self):
return self._get_tweet(self._get_tag())