-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (44 loc) · 1.33 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
# Importing Tweepy
import asyncio
import os
from twitterapi import TwitterUIFlow
from config import SERVER_URL, SLEEP_TIME
from utils import BTCTicker, ping_server
if SERVER_URL:
from threading import Thread
from flask import Flask, jsonify
app = Flask("")
@app.route("/")
def main():
res = {"status": "running"}
return jsonify(res)
def run():
app.run(port=8000)
async def keep_alive():
server = Thread(target=run)
server.start()
async def tweet_the_price(flow: TwitterUIFlow):
info_message, detail_message = await BTCTicker()
flow.CreateTweet(info_message)
tweet_id = flow.content["data"]["create_tweet"]["tweet_results"]["result"][
"rest_id"
]
flow.CreateTweet(detail_message, in_reply_to_tweet_id=tweet_id)
async def main():
if SERVER_URL:
await keep_alive()
asyncio.create_task(ping_server())
flow = TwitterUIFlow()
flow.LoadCookies("cookies.json")
while True:
try:
await tweet_the_price(flow)
except Exception as e:
print(e)
await asyncio.sleep(SLEEP_TIME)
if __name__ == "__main__":
print("Bot started Running")
if not os.path.exists("cookies.json"):
print("Please Login to Twitter by\n\npython login.py")
exit()
asyncio.run(main())