warp-beacon 2.2.0__py3-none-any.whl → 2.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- __version__ = "2.2.0"
1
+ __version__ = "2.2.1"
2
2
 
@@ -1,4 +1,7 @@
1
+ import os
2
+ import time
1
3
  import threading
4
+ import json
2
5
 
3
6
  from warp_beacon.jobs import Origin
4
7
  import warp_beacon
@@ -6,10 +9,12 @@ import warp_beacon
6
9
  import logging
7
10
 
8
11
  class IGScheduler(object):
12
+ state_file = "/var/warp_beacon/scheduler_state.json"
9
13
  downloader = None
10
14
  running = True
11
15
  thread = None
12
16
  event = None
17
+ state = {"remaining": 3600}
13
18
 
14
19
  def __init__(self, downloader: warp_beacon.scraper.AsyncDownloader) -> None:
15
20
  self.downloader = downloader
@@ -18,6 +23,23 @@ class IGScheduler(object):
18
23
  def __del__(self) -> None:
19
24
  self.stop()
20
25
 
26
+ def save_state(self) -> None:
27
+ try:
28
+ with open(self.state_file, 'w+', encoding="utf-8") as f:
29
+ f.write(json.dumps(self.state))
30
+ except Exception as e:
31
+ logging.error("Failed to save Scheduler state!")
32
+ logging.exception(e)
33
+
34
+ def load_state(self) -> None:
35
+ try:
36
+ if os.path.exists(self.state_file):
37
+ with open(self.state_file, 'r', encoding="utf-8") as f:
38
+ self.state = json.loads(f.read())
39
+ except Exception as e:
40
+ logging.error("Failed to load Scheduler state!")
41
+ logging.exception(e)
42
+
21
43
  def start(self) -> None:
22
44
  self.thread = threading.Thread(target=self.do_work)
23
45
  self.thread.start()
@@ -55,11 +77,20 @@ class IGScheduler(object):
55
77
 
56
78
  def do_work(self) -> None:
57
79
  logging.info("Scheduler thread started ...")
80
+ self.load_state()
81
+ timeout = self.state["remaining"]
58
82
  while self.running:
59
83
  try:
60
84
  logging.info("Scheduler waking up")
85
+ start_time = time.time()
61
86
  self.validate_ig_session()
62
- self.event.wait(timeout=3600)
87
+ self.event.wait(timeout=timeout)
88
+ elapsed = time.time() - start_time
89
+ self.state["remaining"] = timeout - elapsed
90
+
91
+ if self.state["remaining"] <= 0:
92
+ self.state["remaining"] = 3600
63
93
  except Exception as e:
64
94
  logging.error("An error occurred in scheduler thread!")
65
- logging.exception(e)
95
+ logging.exception(e)
96
+ self.save_state()
@@ -170,6 +170,7 @@ class Bot(object):
170
170
  )
171
171
  else:
172
172
  args["video"] = job.tg_file_id.replace(":video", '')
173
+ args["caption"] = self.build_signature_caption(job)
173
174
  else:
174
175
  if job.placeholder_message_id:
175
176
  args["media"] = InputMediaVideo(
@@ -200,6 +201,7 @@ class Bot(object):
200
201
  )
201
202
  else:
202
203
  args["photo"] = job.tg_file_id.replace(":image", '')
204
+ args["caption"] = self.build_signature_caption(job)
203
205
  else:
204
206
  if job.placeholder_message_id:
205
207
  args["media"] = InputMediaPhoto(
@@ -208,6 +210,7 @@ class Bot(object):
208
210
  )
209
211
  else:
210
212
  args["photo"] = job.local_media_path
213
+ args["caption"] = self.build_signature_caption(job)
211
214
  elif job.media_type == JobType.AUDIO:
212
215
  if job.tg_file_id:
213
216
  if job.placeholder_message_id:
@@ -239,10 +242,12 @@ class Bot(object):
239
242
  if job.tg_file_id:
240
243
  if job.placeholder_message_id:
241
244
  args["media"] = InputMediaAnimation(
242
- media=job.tg_file_id.replace(":animation", '')
245
+ media=job.tg_file_id.replace(":animation", ''),
246
+ caption=self.build_signature_caption(job)
243
247
  )
244
248
  else:
245
249
  args["animation"] = job.tg_file_id.replace(":animation", '')
250
+ args["caption"] = self.build_signature_caption(job)
246
251
  else:
247
252
  if job.placeholder_message_id:
248
253
  args["media"] = InputMediaAnimation(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: warp_beacon
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: Telegram bot for expanding external media links
5
5
  Home-page: https://github.com/sb0y/warp_beacon
6
6
  Author: Andrey Bagrintsev
@@ -3,7 +3,7 @@ lib/systemd/system/warp_beacon.service,sha256=lPmHqLqcI2eIV7nwHS0qcALQrznixqJuww
3
3
  var/warp_beacon/accounts.json,sha256=rKFQM_b9eoDS4mJ1B_SZNolPLXx1SQdQMdY2F_ZcBt8,1523
4
4
  var/warp_beacon/placeholder.gif,sha256=cE5CGJVaop4Sx21zx6j4AyoHU0ncmvQuS2o6hJfEH88,6064
5
5
  warp_beacon/__init__.py,sha256=_rThNODmz0nDp_n4mWo_HKaNFE5jk1_7cRhHyYaencI,163
6
- warp_beacon/__version__.py,sha256=WMCzR_QnD3JzFHSeOqgJDoy5dvPLvgg2SMbWaTYllMs,23
6
+ warp_beacon/__version__.py,sha256=AmBkr7ARRWHmff4IC1Z-mqL0cMMtNqSb8LKSY7kfXXc,23
7
7
  warp_beacon/warp_beacon.py,sha256=7KEtZDj-pdhtl6m-zFLsSojs1ZR4o7L0xbqtdmYPvfE,342
8
8
  warp_beacon/compress/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  warp_beacon/compress/video.py,sha256=_PDMVYCyzLYxHv1uZmmzGcG_8rjaZr7BTXsXTTy_oS4,2846
@@ -18,7 +18,7 @@ warp_beacon/mediainfo/audio.py,sha256=ous88kwQj4bDIChN5wnGil5LqTs0IQHH0d-nyrL0-Z
18
18
  warp_beacon/mediainfo/silencer.py,sha256=MgUc9Ibbhjhg9GbJMNfJqrdDkMsQShZkQ1sCwvW_-qI,1647
19
19
  warp_beacon/mediainfo/video.py,sha256=AIRy_op_BvehsjarM1rvT5Qo0QWwf-Q6xVVd_aCnbJ4,2505
20
20
  warp_beacon/scheduler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- warp_beacon/scheduler/scheduler.py,sha256=BO9nzJ2oKK877527HrzztBBOSClt5cAK1jGmO7gv38c,1536
21
+ warp_beacon/scheduler/scheduler.py,sha256=OtUnXPf83Uhe6j7VCwpW4KWasOPB5OXy9v471Ra42Ss,2436
22
22
  warp_beacon/scraper/__init__.py,sha256=0ZxLxzXweg1LJ1qBRJ1s3EOKe7xpUrp9Nj26gjsLMOQ,14734
23
23
  warp_beacon/scraper/abstract.py,sha256=aNZ9ypF9B8BjflcIwi-7wEzIqF-XPeF0xvfX9CP_iIw,2708
24
24
  warp_beacon/scraper/account_selector.py,sha256=RYBmLDhE-fqaLqQiQ6zVd13q-1pqQ3F3nYJu2Gx3gV4,2881
@@ -32,14 +32,14 @@ warp_beacon/scraper/youtube/shorts.py,sha256=pHfvEBau8Zp7Ar3LBuPmjqYq8fmjJUQvzeZ
32
32
  warp_beacon/scraper/youtube/youtube.py,sha256=K98n2TSJaDZt-xT7mADZL1UEf2exIYm0Wnenn2GAYfI,2250
33
33
  warp_beacon/storage/__init__.py,sha256=8XsJXq9X7GDlTaWREF4W1PDX9PH5utwhjf5c5M8Bb7o,3378
34
34
  warp_beacon/telegram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
- warp_beacon/telegram/bot.py,sha256=lH_0oQCsJOLLAwQVzFAOiSW4wm7-UQrKZRDd-PzDfiU,14792
35
+ warp_beacon/telegram/bot.py,sha256=khk2NvVz_UvxEA_Cz43D5jFuV4z_mUNLOXLhwXKUxz8,15069
36
36
  warp_beacon/telegram/handlers.py,sha256=ccqUY7YbddDNbTxYVxpDPjLVJmcAL14yoaQ7xT9WBLU,6725
37
37
  warp_beacon/telegram/placeholder_message.py,sha256=u5kVfTjGmVYkwA5opniRltHXGpsdSxI41WEde8J5os0,6418
38
38
  warp_beacon/telegram/utils.py,sha256=ikfwmuDvd0XtOuwP29tZPjAz7kwiGSSu_QR-vpv6pMY,2352
39
39
  warp_beacon/uploader/__init__.py,sha256=rsUkzzmtaeQY-kNkcIiPsrayS9idFKY3hBC71mR19XE,4743
40
- warp_beacon-2.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
- warp_beacon-2.2.0.dist-info/METADATA,sha256=LyrV1URH8gNbGV57ZTyyWGzuIC4UrrBvLzZR_a-AcVw,21250
42
- warp_beacon-2.2.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
43
- warp_beacon-2.2.0.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
44
- warp_beacon-2.2.0.dist-info/top_level.txt,sha256=ALb_Ft_eG-OY4_m0TWUifNUOZsrx483L-zw7G7vqXoc,971
45
- warp_beacon-2.2.0.dist-info/RECORD,,
40
+ warp_beacon-2.2.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
+ warp_beacon-2.2.1.dist-info/METADATA,sha256=LU8S-4Q189DPmiDq9rx4tdfyKJjCIvsSgInmaja0PqQ,21250
42
+ warp_beacon-2.2.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
43
+ warp_beacon-2.2.1.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
44
+ warp_beacon-2.2.1.dist-info/top_level.txt,sha256=ALb_Ft_eG-OY4_m0TWUifNUOZsrx483L-zw7G7vqXoc,971
45
+ warp_beacon-2.2.1.dist-info/RECORD,,