Compare commits
2 commits
55c0733a40
...
d7e74db703
Author | SHA1 | Date | |
---|---|---|---|
d7e74db703 | |||
cd2a8f0d7b |
1 changed files with 38 additions and 2 deletions
40
main.py
Normal file → Executable file
40
main.py
Normal file → Executable file
|
@ -2,11 +2,12 @@
|
||||||
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,
|
||||||
"mark_sensitive":True
|
"mark_sensitive":True,
|
||||||
|
"site":"https://botsin.space"
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
j = json.load(open("config.json"))
|
j = json.load(open("config.json"))
|
||||||
|
@ -52,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