check usernames, create database
This commit is contained in:
parent
cd2a8f0d7b
commit
d7e74db703
1 changed files with 36 additions and 1 deletions
37
main.py
37
main.py
|
@ -2,7 +2,7 @@
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
import twitter
|
import twitter
|
||||||
|
|
||||||
import sqlite3, json
|
import sqlite3, json, re
|
||||||
|
|
||||||
cfg = {
|
cfg = {
|
||||||
"cw":None,
|
"cw":None,
|
||||||
|
@ -53,9 +53,44 @@ if "twitter" not in cfg:
|
||||||
|
|
||||||
json.dump(cfg, open("config.json", "w+"))
|
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 = Mastodon(
|
||||||
client_id=cfg['client']['id'],
|
client_id=cfg['client']['id'],
|
||||||
client_secret = cfg['client']['secret'],
|
client_secret = cfg['client']['secret'],
|
||||||
access_token=cfg['secret'],
|
access_token=cfg['secret'],
|
||||||
api_base_url=cfg['site'])
|
api_base_url=cfg['site'])
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue