-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdogebot.py
75 lines (60 loc) · 1.84 KB
/
dogebot.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
import os
import re
import datetime
import schedule
import time
from dotenv import load_dotenv
from binance import Client
import tweepy
# Functions
from analyse_tweet import analyse_tweet
load_dotenv()
# Api Keys
binance_api_key = os.getenv('BINANCE_API')
binance_api_secret = os.getenv('BINANCE_SECRET')
twitter_api_key = os.getenv('CONSUMER_KEY')
twitter_api_secret = os.getenv('CONSUMER_SECRET')
twitter_api_token = os.getenv('ACCESS_TOKEN')
twitter_api_secret_token = os.getenv('ACCESS_TOKEN_SECRET')
# Binance API
client = Client(binance_api_key, binance_api_secret)
# Twitter API
auth = tweepy.OAuthHandler(twitter_api_key, twitter_api_secret)
auth.set_access_token(twitter_api_token, twitter_api_secret_token)
twitter_api = tweepy.API(auth, wait_on_rate_limit=True)
# #
# Check for new tweets
# #
def checkForNewTweet(twitter_api):
print('🟢 Checking tweets..' + '\n')
# Elon musk most recent tweet
tweets = twitter_api.user_timeline(
screen_name="elonmusk",
count=1,
lang="en",
tweet_mode="extended",
include_rts=False,
)
if tweets:
# Tweet text
tweet = tweets[0].full_text
print('Current tweet :', datetime.datetime.now(), tweet)
# Parse Tweet
no_punct = re.sub(r'[\W\s]', ' ', tweet)
tweet = no_punct
# Get the minute since tweet
time_difference = datetime.datetime.now().minute - \
tweets[0].created_at.minute
# If tweet is less than 3 min old, analyse and buy
if time_difference <= 3 or time_difference == 0:
analyse_tweet(tweet, client)
else:
return
else:
return
if __name__ == "__main__":
checkForNewTweet(twitter_api)
schedule.every(60).seconds.do(checkForNewTweet, twitter_api)
while 1:
schedule.run_pending()
time.sleep(1)