-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountview.py
More file actions
40 lines (34 loc) · 1.2 KB
/
countview.py
File metadata and controls
40 lines (34 loc) · 1.2 KB
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
import time
import requests
BOT_TOKEN = '7333437316:-'
CHANNEL_ID = '@'
VIEW_THRESHOLD = 500000
WAIT_TIME = 1800
API_URL = 'https://api.telegram.org'
def get_posts():
url = f"{API_URL}/bot{BOT_TOKEN}/getUpdates"
response = requests.get(url).json()
posts = [update['message'] for update in response['result'] if 'message' in update and 'text' in update['message']]
return posts
def get_post_views(post_id):
url = f"{API_URL}/bot{BOT_TOKEN}/getMessage?chat_id={CHANNEL_ID}&message_id={post_id}"
response = requests.get(url).json()
return response['result'].get('views', 0)
def process_posts():
posts = get_posts()
for post in posts:
post_id = post['message_id']
while True:
views = get_post_views(post_id)
if views >= VIEW_THRESHOLD:
print(f"Post {post_id} has reached {VIEW_THRESHOLD} views.")
break
print(f"Waiting for post {post_id} to reach {VIEW_THRESHOLD} views. Current views: {views}")
time.sleep(WAIT_TIME)
time.sleep(WAIT_TIME)
def handler(request):
process_posts()
return {
"statusCode": 200,
"body": "Posts processed successfully."
}