a couple libraries and even MORE restructuring
This commit is contained in:
+44
-5
@@ -1,7 +1,11 @@
|
||||
## Shared utility functions.
|
||||
|
||||
import os
|
||||
import talent_lists
|
||||
|
||||
import twint
|
||||
from tweetcapture import TweetCapture
|
||||
|
||||
from talent_lists import *
|
||||
import talenttweet as tt
|
||||
|
||||
# returns system path to this project, which is
|
||||
@@ -9,8 +13,43 @@ import talenttweet as tt
|
||||
def get_project_dir():
|
||||
return os.path.join(os.path.dirname(__file__), os.pardir)
|
||||
|
||||
def tweet_id_to_url(id):
|
||||
return f'https://twitter.com/twitter/status/{id}'
|
||||
|
||||
def clamp(n, smallest, largest):
|
||||
return max(smallest, min(n, largest))
|
||||
return max(smallest, min(n, largest))
|
||||
|
||||
async def create_ttweet_image(ttweet):
|
||||
tc = TweetCapture()
|
||||
filename = 'img.png'
|
||||
url = ttweet_to_url(ttweet)
|
||||
img = None
|
||||
|
||||
try: os.remove(filename)
|
||||
except: pass
|
||||
try:
|
||||
img = await tc.screenshot(
|
||||
url=url,
|
||||
path=filename,
|
||||
mode=4,
|
||||
night_mode=1
|
||||
)
|
||||
except:
|
||||
print('unable to create tweet image')
|
||||
return None
|
||||
else:
|
||||
print(f'successfully saved {img}')
|
||||
return img
|
||||
|
||||
def ttweet_to_url(ttweet):
|
||||
username = get_username(ttweet.author_id)
|
||||
return f'https://twitter.com/{username}/status/{ttweet.tweet_id}'
|
||||
|
||||
def get_username(user_id):
|
||||
c = twint.Config()
|
||||
c.User_id = user_id
|
||||
c.Store_object = True
|
||||
c.Hide_output = True
|
||||
try:
|
||||
twint.run.Lookup(c)
|
||||
user = twint.output.users_list[0]
|
||||
return user.username
|
||||
except:
|
||||
return talents.get(user_id, f'#{user_id}')
|
||||
Reference in New Issue
Block a user