-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (33 loc) · 1.3 KB
/
main.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
37
38
39
40
41
42
43
44
45
#! /usr/bin/env python3
# coding: utf-8
import json
import sys
import wikiquote_import as wq_imp
import twitter_config as tw_conf
import datetime as dt
# Name: Wikiquote Twitter Bot
# Desc: A simple way to tweet famous quotes from Wikiquote
# Repo: https://github.com/IamPhytan/wikiquote-twitter-bot
# Author: IamPhytan
# License: MIT
# Path: -
if __name__ == '__main__':
assert (sys.version_info[0] >= 3), "Python 3 or a more recent version is required."
with open('config.json', 'r') as f:
config = json.load(f)
# ========== QUOTES ==========
quotes = wq_imp.get_quotes(config)
quotes_to_send = [pot_tweet for pot_tweet in quotes if len(pot_tweet) <= 280]
# ========== TIME CONFIG ==========
h = config['TIME']['HOUR']
m = config['TIME']['MINUTE']
s = config['TIME']['SECOND']
# ========== TWITTER ==========
tw_api = tw_conf.create_twitter_config(config)
used_tweets_idxs = list()
# TODO Change logic to use crontab instead
while len(used_tweets_idxs) < len(quotes_to_send):
curr_tm = dt.datetime.now().time()
if (curr_tm.hour, curr_tm.minute, curr_tm.second, curr_tm.microsecond) == (h, m, s, 0):
used_tweets_idxs = tw_conf.choose_quote_n_tweet(quotes_to_send, used_tweets_idxs, tw_api)
print("Add more quotes")