include co. name in msg, filter mentions to co.

This commit is contained in:
muskit
2023-01-13 02:55:25 -08:00
parent 68ac59d5c5
commit a9188fe07a
4 changed files with 33 additions and 11 deletions
+7
View File
@@ -30,15 +30,22 @@ def run():
sc = tweepy.StreamingClient(api_secrets.bearer_token())
# clear rules
print('Clearing streaming rules...')
rules_resp = sc.get_rules()
if rules_resp.data:
print('Deleted a rule!')
sc.delete_rules(rules_resp.data)
# create new rules
print('Creating new streaming rules...')
for rule in tl.get_twitter_rules():
sc.add_rules(tweepy.StreamRule(rule))
print('--------------------------------------------')
print(sc.get_rules().data)
print('--------------------------------------------')
sc.on_response=on_response
print('Starting listening stream...')
sc.filter(
expansions=TwAPI.TWEET_EXPANSIONS,
media_fields=TwAPI.TWEET_MEDIA_FIELDS,
+11 -9
View File
@@ -8,7 +8,8 @@ talents = dict()
test_talents = dict()
def __create_dict(file, _dict):
# TODO: talents(id) -> (name, company)
def __create_dict(file, _dict, company):
print(f'Initializing talents\' account list from {file}...')
global talents
with open(file, 'r') as f:
@@ -16,7 +17,7 @@ def __create_dict(file, _dict):
words = line.split()
if len(words) == 2 and line[0] != '#':
name, id = line.split()
name = util.get_username_online(id, default=name) # attempt to get updated name
name = f'{util.get_username_online(id, default=name)} ({company})' # attempt to get updated name
talents[int(id)] = name
_dict[int(id)] = name
def init():
@@ -27,13 +28,14 @@ def init():
global test_talents
# holoEN
__create_dict(f'{util.get_project_dir()}/lists/holoen.txt', holo_en)
__create_dict(f'{util.get_project_dir()}/lists/holoen.txt', holo_en, 'holoEN')
# holoID
__create_dict(f'{util.get_project_dir()}/lists/holoid.txt', holo_id)
__create_dict(f'{util.get_project_dir()}/lists/holoid.txt', holo_id, 'holoID')
# nijiEN
__create_dict(f'{util.get_project_dir()}/lists/nijien.txt', niji_en)
__create_dict(f'{util.get_project_dir()}/lists/nijien.txt', niji_en, 'nijiEN')
# nijiexID
__create_dict(f'{util.get_project_dir()}/lists/nijiexid.txt', niji_exid)
__create_dict(f'{util.get_project_dir()}/lists/nijiexid.txt', niji_exid, 'nijiex-ID')
# TODO: nijiex-KR
test_talents = holo_en
@@ -42,12 +44,12 @@ def get_twitter_rules():
rules = list()
names = list(talents.values())
curr_rule = f'from:{names[0]}'
curr_rule = f'from:{names[0].split()[0]}'
for name in list(talents.values())[1:]:
test_rule = curr_rule + f' OR from:{name}'
test_rule = curr_rule + f' OR from:{name.split()[0]}'
if len(test_rule) > 512:
rules.append(curr_rule)
curr_rule = f'from:{name}'
curr_rule = f'from:{name.split()[0]}'
else:
curr_rule = test_rule
return rules
+11 -1
View File
@@ -6,6 +6,7 @@ import tweepy
import api_secrets
import talenttweet as tt
import talent_lists as tl
import util
class TwAPI:
@@ -22,6 +23,8 @@ class TwAPI:
# media_fields=['url'],
# tweet_fields=['created_at', 'in_reply_to_user_id'],
# expansions=['entities.mentions.username', 'referenced_tweets.id.author_id']
#
# VALUES IN TUPLE ARE NONE OR INT.
@staticmethod
def get_mrq(response):
tweet = response.data
@@ -54,6 +57,13 @@ class TwAPI:
try:
mentions.remove(qrt)
except: pass
mention_list = list(mentions)
for uid in mention_list:
if uid not in tl.talents.keys():
mentions.remove(uid)
if reply_to not in tl.talents.keys():
reply_to = None
return (mentions, reply_to, qrt)
@@ -215,7 +225,7 @@ class TwAPI:
mention_usernames = [f'@/{util.get_username(x)}' for x in print_mention_ids]
ret += (
'mentioning '
f'{" ".join(mention_usernames)}\n'
f'{", ".join(mention_usernames)}\n'
)
ret += '\n'
ret += '(this is a missed tweet)\n' if is_catchup else ''
+4 -1
View File
@@ -1,6 +1,7 @@
## Shared utility functions.
import os
import sys
import traceback
from datetime import datetime
@@ -52,7 +53,9 @@ def get_key_from_value(d, val):
async def create_ttweet_image(ttweet):
tc = TweetCapture()
tc.driver_path = '/usr/bin/chromedriver' # Linux chromedriver path
if 'linux' in sys.platform:
# Linux chromedriver path
tc.driver_path = '/usr/bin/chromedriver'
filename = f'{get_project_dir()}/img.png'
url = ttweet_to_url(ttweet)
img = None