-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (69 loc) · 2.34 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#reejit/refreshingpics
from pyrogram import Client
from requests import get
import os
from os import remove
from asyncio import sleep, new_event_loop
from random import choice
import random
# Imported all fu**ing libraries
#main function 👇
async def run():
#creating telegram objecta
bot = Client(
name=("ʀᴇꜰʀᴇꜱʜɪɴɢᴘɪᴄꜱ"),
api_id=int(os.environ.get("API_ID")),
api_hash=os.environ.get("HASH"),
bot_token=os.environ.get("TOKEN"),
no_updates=True,
app_version="refershing1.3.1"
)
#getting chat_id passed as str like for @refreshingpics it's refreshingpics
chat_id = os.environ.get("CHAT_ID")
#starting bot otherwise throws error
await bot.start()
#infine loop 🔁
while True:
list = ["https://source.unsplash.com/random","https://source.unsplash.com/random","https://source.unsplash.com/random", "https://picsum.photos/1080/1920","https://loremflickr.com/1080/1920"]
#chooshing random url because sometimes two bots tend to send same photos (at the same time).
no = choice(list)
url = get(no).url
file = f"{random.randint(0, 9999)}.jpg"
try:
await bot.send_photo(chat_id, photo=url)
except Exception as e:
#maybe floodwait 420 or Telegram CURL failed 400
print(e)
try:
x = e.value
print("{} seconds".format(x))
#handled 420 error
await sleep(x)
await bot.send_photo(chat_id, photo=url)
#incase 400
except Exception as e:
print(e)
from wget import download
try:
download(url, file)
except Exception:
print(Exception)
run()
from pyrogram.errors import FloodWait
try:
#incase 420 still exists
await bot.send_photo(chat_id, photo=file)
except FloodWait as e:
x = e.value
print("{} seconds".format(x))
await sleep(x)
#keeping memory free 😋
try:
remove(file)
except:
pass
if __name__ == "__main__":
#keep_alive()
#running asynchronous
loop = new_event_loop()
loop.run_until_complete(run())