Compare commits

...

2 Commits

Author SHA1 Message Date
Lynne Megido d7e74db703
check usernames, create database 2019-02-27 13:38:10 +10:00
Lynne Megido cd2a8f0d7b
added a missing config variable 2019-02-26 14:38:21 +10:00

40
main.py Normal file → Executable file
View File

@ -2,11 +2,12 @@
from mastodon import Mastodon
import twitter
import sqlite3, json
import sqlite3, json, re
cfg = {
"cw":None,
"mark_sensitive":True
"mark_sensitive":True,
"site":"https://botsin.space"
}
try:
j = json.load(open("config.json"))
@ -52,9 +53,44 @@ if "twitter" not in cfg:
json.dump(cfg, open("config.json", "w+"))
# log in to twitter
api = twitter.Api(**cfg['twitter'])
if "accounts" not in cfg:
print("Please specify the accounts you'd like Twitter Image Poster to learn from. Enter one account at a time formatted as '@user', followed by a blank line.")
i = None
accounts = []
while i != "":
i = input("User: ")
if not re.match("@(\w){1,15}$", i):
print("Invalid username")
continue
if i == "" and len(accounts) == 0:
print("You must enter at least one account")
continue
print("Checking account...")
print(api.GetUser(screen_name=i))
# connect to database
db = sqlite3.connect("tip.db")
db.text_factory=str
c = db.cursor()
c.execute("CREATE TABLE IF NOT EXISTS `images` (post_id INT NOT NULL UNIQUE PRIMARY KEY, user_id INT NOT NULL, image_url VARCHAR) WITHOUT ROWID")
db.commit()
last_tweet = c.execute("SELECT post_id FROM `images` WHERE user_id LIKE ? ORDER BY post_id DESC LIMIT 1", (f.id,)).fetchone()
print("Downloading tweets from {}".format())
client = Mastodon(
client_id=cfg['client']['id'],
client_secret = cfg['client']['secret'],
access_token=cfg['secret'],
api_base_url=cfg['site'])