-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.py
More file actions
39 lines (32 loc) · 1.45 KB
/
stream.py
File metadata and controls
39 lines (32 loc) · 1.45 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
import tweepy
import logging
from tokens import *
from mint import create_nft
from grab_pfp import grab_pfp
from username import get_username
from upload_file import send_post
from image_format import image_to_json
from reply_tweet import base_comment, reply_nft
class MyStream(tweepy.Stream):
def __init__(self, consumer_key, consumer_secret, access_token, access_token_secret, api, **kwargs):
self.api = api
super().__init__(consumer_key, consumer_secret, access_token, access_token_secret, **kwargs)
def on_status(self, status):
logging.info(f"{status.user.screen_name} tweeted: {status.text}")
parent = get_username(api=self.api, reply_tweet=status)
if parent is None:
base_comment(self.api, status)
else:
logging.info(f"Parent comment is from user {parent.screen_name}.")
link = grab_pfp(user=parent)
logging.info(f"{parent.screen_name}'s profile picture: {link}.")
json_str = image_to_json(link)
w3_storage_url = send_post(json_str)
hex_hash = create_nft(w3_storage_url)
print('nft gen success', hex_hash)
out = reply_nft(self.api, status)
print(out)
return super().on_status(status)
def streamTweets(hashtags: list[str]):
myStreamListener = MyStream(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
myStreamListener.filter(track=hashtags)