143 lines
3.8 KiB
Python
Executable File
143 lines
3.8 KiB
Python
Executable File
#! /usr/bin/env python
|
|
|
|
import ipdb
|
|
import pickle
|
|
import random
|
|
import stackprinter
|
|
import sys
|
|
|
|
from config import Config
|
|
from dbconfig import engine, Session, scoped_session
|
|
from log import log
|
|
from mastodon import Mastodon
|
|
from models import (
|
|
Accounts,
|
|
Attachments,
|
|
Base,
|
|
Hashtags,
|
|
Posts,
|
|
PostTags,
|
|
)
|
|
|
|
from PyQt5.QtWidgets import (
|
|
QApplication,
|
|
QLabel,
|
|
QMainWindow,
|
|
QPushButton,
|
|
)
|
|
|
|
from ui.main_window_ui import Ui_MainWindow # type: ignore
|
|
|
|
TESTDATA = "/home/kae/git/urma/hometl.pickle"
|
|
|
|
# Mastodon.create_app(
|
|
# 'urma',
|
|
# api_base_url='mastodon.org.uk',
|
|
# to_file='urma_clientcred.secret'
|
|
# )
|
|
|
|
# API_BASE_URL = 'mastodon.org.uk'
|
|
|
|
# mastodon = Mastodon(client_id = 'urma_clientcred.secret',)
|
|
# mastodon.log_in('kae@midnighthax.com', '^ZUaiC8P6vLV49',
|
|
# to_file='urma_usercred.secret')
|
|
# hometl = Mastodon.timeline()
|
|
# hometl = mastodon.timeline()
|
|
# hometl
|
|
# len(hometl)
|
|
# hometl0=hometl[0]
|
|
# hometl0
|
|
# history
|
|
# mastodon.me()
|
|
# following=mastodon.account_following(kaeid)
|
|
# len(following)
|
|
# following[0]
|
|
# following[39]
|
|
# following._pagination_next
|
|
# following._pagination_prev
|
|
# history
|
|
|
|
# mastodon = mastodon(access_token=Config.ACCESS_TOKEN)
|
|
|
|
|
|
class Window(QMainWindow, Ui_MainWindow):
|
|
def __init__(self, parent=None) -> None:
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
|
|
|
|
# class HoldingPot:
|
|
# def process_post(post):
|
|
# rec = Posts.get_or_create(session, str(post.id))
|
|
# if rec.account_id is not None:
|
|
# # We already have this post
|
|
# return
|
|
#
|
|
# # Create account record if needed
|
|
# account_rec = Accounts.get_or_create(session, str(post.account.id))
|
|
# if account_rec.username is None:
|
|
# account_rec.username = post.account.username
|
|
# account_rec.acct = post.account.acct
|
|
# account_rec.display_name = post.account.display_name
|
|
# account_rec.bot = post.account.bot
|
|
# account_rec.url = post.account.url
|
|
# rec.account_id = account_rec.id
|
|
#
|
|
# # Create hashtag records as needed
|
|
# for tag in post.tags:
|
|
# hashtag = Hashtags.get_or_create(session, tag.name, tag.url)
|
|
# rec.hashtags.append(hashtag)
|
|
#
|
|
# # Handle media
|
|
# for media in post.media_attachments:
|
|
# media_rec = Attachments.get_or_create(session,
|
|
# str(media.id), rec.id)
|
|
# if not media_rec.type:
|
|
# media_rec.type = media.type
|
|
# media_rec.url = media.url
|
|
# media_rec.preview_url = media.preview_url
|
|
# media_rec.description = media.description
|
|
#
|
|
# rec.account_id = account_rec.id
|
|
# rec.created_at = post.created_at
|
|
# rec.uri = post.uri
|
|
# rec.url = post.url
|
|
# rec.content = post.content
|
|
#
|
|
# if post.reblog:
|
|
# rec.child_id = process_post(post.reblog).id
|
|
#
|
|
# return rec
|
|
#
|
|
# # Data for development
|
|
# with open(TESTDATA, "rb") as inp:
|
|
# hometl = pickle.load(inp)
|
|
#
|
|
# with Session() as session:
|
|
# for post in hometl:
|
|
# process_post(post)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
"""
|
|
If command line arguments given, carry out requested function and
|
|
exit. Otherwise run full application.
|
|
"""
|
|
|
|
try:
|
|
Base.metadata.create_all(engine)
|
|
app = QApplication(sys.argv)
|
|
win = Window()
|
|
win.show()
|
|
sys.exit(app.exec())
|
|
except Exception as exc:
|
|
from helpers import send_mail
|
|
|
|
msg = stackprinter.format(exc)
|
|
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
|
|
"Exception from urma", msg)
|
|
|
|
print("\033[1;31;47mUnhandled exception starts")
|
|
stackprinter.show(style="darkbg")
|
|
print("Unhandled exception ends\033[1;37;40m")
|