basyx commited on
Commit
2bc2e0b
·
verified ·
1 Parent(s): b833da8

Create publisher_ai.py

Browse files
Files changed (1) hide show
  1. publisher/publisher_ai.py +68 -0
publisher/publisher_ai.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # publisher/publisher_ai.py
2
+
3
+ import asyncio
4
+
5
+ from publisher.scheduler_engine import (
6
+ next_jobs,
7
+ mark_done
8
+ )
9
+
10
+ from publisher.account_manager import (
11
+ connected_accounts,
12
+ choose_platforms
13
+ )
14
+
15
+ from publisher.metadata_engine import generate_metadata
16
+ from publisher.thumbnail_engine import generate_thumbnail
17
+ from publisher.platform_dispatcher import dispatch
18
+
19
+
20
+ async def process_job(job):
21
+
22
+ job_id, user_id, video = job
23
+
24
+ print("Processing:", video)
25
+
26
+ accounts = connected_accounts(user_id)
27
+
28
+ if not accounts:
29
+ print("No connected accounts")
30
+ return
31
+
32
+ metadata = await generate_metadata(video)
33
+
34
+ thumb = generate_thumbnail(
35
+ metadata["title"],
36
+ f"thumbnails/{job_id}.jpg"
37
+ )
38
+
39
+ targets = choose_platforms(
40
+ "short_video",
41
+ accounts
42
+ )
43
+
44
+ for acc in targets:
45
+
46
+ await dispatch(
47
+ acc["platform"],
48
+ acc["token"],
49
+ video,
50
+ metadata,
51
+ thumb
52
+ )
53
+
54
+ mark_done(job_id)
55
+
56
+
57
+ async def autonomous_loop():
58
+
59
+ print("Publisher AI Started")
60
+
61
+ while True:
62
+
63
+ jobs = next_jobs()
64
+
65
+ for job in jobs:
66
+ await process_job(job)
67
+
68
+ await asyncio.sleep(30)