-
Notifications
You must be signed in to change notification settings - Fork 19
/
__main__.py
61 lines (52 loc) · 2.26 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import asyncio,tts,os,video,requests
import imp
from scraper import scrape
from upload import upload_to_tiktok
from utils import config
async def main():
# Fetching posts from r/AskReddit
headers = { 'user-agent':'py-reddit-scraping:0:1.0 (by u/ur_name)' }
posts = requests.get('https://www.reddit.com/r/AskReddit/top.json?t=day&limit=30', headers=headers).json()['data']['children']
for post in posts:
try:
# Avoid getting banned, no NSFW posts
if 'nsfw' in post['data']['whitelist_status']:
continue
url = post['data']['url']
name = url.split('/')[-2]
print(f"⏱ Processing post: {name}")
# Make sure we have not already rendered/uploaded post
if name in [entry.split('.')[0] for entry in os.listdir('render')]:
print("❌ Post already processed!")
continue
# Clean 'temporary' files from last video
for file in os.listdir('output'):
os.remove(f'output/{file}')
# Scraping the post, screenshotting, etc
print("📸 Screenshotting post...")
data = scrape(url)
if not data:
print("❌ Failed to screenshot post!")
continue
# Generate TTS clips for each comment
print("\n📢 Generating voice clips...",end="",flush=True)
voice = await tts.get_voice()
for key in data.keys():
print('.',end="",flush=True)
await tts.generate(data[key], key, voice)
# Render & Upload
print("\n🎥 Rendering video...")
if video.render(name):
# Upload video if rendered
print("🌟 Uploading to TikTok...")
if upload_to_tiktok(name,data["post"]):
print("✅ Uploaded successfully!")
else:
print("❌ Failed to upload!")
except Exception as e:
if config['debug']:
raise e
pass
if __name__ == '__main__':
[os.mkdir(dir) for dir in ['output','render','backgrounds'] if not os.path.exists(dir)]
asyncio.run(main())