include co. name in msg, filter mentions to co.
This commit is contained in:
@@ -30,15 +30,22 @@ def run():
|
|||||||
sc = tweepy.StreamingClient(api_secrets.bearer_token())
|
sc = tweepy.StreamingClient(api_secrets.bearer_token())
|
||||||
|
|
||||||
# clear rules
|
# clear rules
|
||||||
|
print('Clearing streaming rules...')
|
||||||
rules_resp = sc.get_rules()
|
rules_resp = sc.get_rules()
|
||||||
if rules_resp.data:
|
if rules_resp.data:
|
||||||
|
print('Deleted a rule!')
|
||||||
sc.delete_rules(rules_resp.data)
|
sc.delete_rules(rules_resp.data)
|
||||||
|
|
||||||
# create new rules
|
# create new rules
|
||||||
|
print('Creating new streaming rules...')
|
||||||
for rule in tl.get_twitter_rules():
|
for rule in tl.get_twitter_rules():
|
||||||
sc.add_rules(tweepy.StreamRule(rule))
|
sc.add_rules(tweepy.StreamRule(rule))
|
||||||
|
print('--------------------------------------------')
|
||||||
|
print(sc.get_rules().data)
|
||||||
|
print('--------------------------------------------')
|
||||||
|
|
||||||
sc.on_response=on_response
|
sc.on_response=on_response
|
||||||
|
print('Starting listening stream...')
|
||||||
sc.filter(
|
sc.filter(
|
||||||
expansions=TwAPI.TWEET_EXPANSIONS,
|
expansions=TwAPI.TWEET_EXPANSIONS,
|
||||||
media_fields=TwAPI.TWEET_MEDIA_FIELDS,
|
media_fields=TwAPI.TWEET_MEDIA_FIELDS,
|
||||||
|
|||||||
+11
-9
@@ -8,7 +8,8 @@ talents = dict()
|
|||||||
|
|
||||||
test_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}...')
|
print(f'Initializing talents\' account list from {file}...')
|
||||||
global talents
|
global talents
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
@@ -16,7 +17,7 @@ def __create_dict(file, _dict):
|
|||||||
words = line.split()
|
words = line.split()
|
||||||
if len(words) == 2 and line[0] != '#':
|
if len(words) == 2 and line[0] != '#':
|
||||||
name, id = line.split()
|
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
|
talents[int(id)] = name
|
||||||
_dict[int(id)] = name
|
_dict[int(id)] = name
|
||||||
def init():
|
def init():
|
||||||
@@ -27,13 +28,14 @@ def init():
|
|||||||
global test_talents
|
global test_talents
|
||||||
|
|
||||||
# holoEN
|
# 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
|
# 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
|
# 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
|
# 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
|
test_talents = holo_en
|
||||||
|
|
||||||
@@ -42,12 +44,12 @@ def get_twitter_rules():
|
|||||||
rules = list()
|
rules = list()
|
||||||
|
|
||||||
names = list(talents.values())
|
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:]:
|
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:
|
if len(test_rule) > 512:
|
||||||
rules.append(curr_rule)
|
rules.append(curr_rule)
|
||||||
curr_rule = f'from:{name}'
|
curr_rule = f'from:{name.split()[0]}'
|
||||||
else:
|
else:
|
||||||
curr_rule = test_rule
|
curr_rule = test_rule
|
||||||
return rules
|
return rules
|
||||||
+11
-1
@@ -6,6 +6,7 @@ import tweepy
|
|||||||
|
|
||||||
import api_secrets
|
import api_secrets
|
||||||
import talenttweet as tt
|
import talenttweet as tt
|
||||||
|
import talent_lists as tl
|
||||||
import util
|
import util
|
||||||
|
|
||||||
class TwAPI:
|
class TwAPI:
|
||||||
@@ -22,6 +23,8 @@ class TwAPI:
|
|||||||
# media_fields=['url'],
|
# media_fields=['url'],
|
||||||
# tweet_fields=['created_at', 'in_reply_to_user_id'],
|
# tweet_fields=['created_at', 'in_reply_to_user_id'],
|
||||||
# expansions=['entities.mentions.username', 'referenced_tweets.id.author_id']
|
# expansions=['entities.mentions.username', 'referenced_tweets.id.author_id']
|
||||||
|
#
|
||||||
|
# VALUES IN TUPLE ARE NONE OR INT.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_mrq(response):
|
def get_mrq(response):
|
||||||
tweet = response.data
|
tweet = response.data
|
||||||
@@ -55,6 +58,13 @@ class TwAPI:
|
|||||||
mentions.remove(qrt)
|
mentions.remove(qrt)
|
||||||
except: pass
|
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)
|
return (mentions, reply_to, qrt)
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +225,7 @@ class TwAPI:
|
|||||||
mention_usernames = [f'@/{util.get_username(x)}' for x in print_mention_ids]
|
mention_usernames = [f'@/{util.get_username(x)}' for x in print_mention_ids]
|
||||||
ret += (
|
ret += (
|
||||||
'mentioning '
|
'mentioning '
|
||||||
f'{" ".join(mention_usernames)}\n'
|
f'{", ".join(mention_usernames)}\n'
|
||||||
)
|
)
|
||||||
ret += '\n'
|
ret += '\n'
|
||||||
ret += '(this is a missed tweet)\n' if is_catchup else ''
|
ret += '(this is a missed tweet)\n' if is_catchup else ''
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
## Shared utility functions.
|
## Shared utility functions.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -52,7 +53,9 @@ def get_key_from_value(d, val):
|
|||||||
|
|
||||||
async def create_ttweet_image(ttweet):
|
async def create_ttweet_image(ttweet):
|
||||||
tc = TweetCapture()
|
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'
|
filename = f'{get_project_dir()}/img.png'
|
||||||
url = ttweet_to_url(ttweet)
|
url = ttweet_to_url(ttweet)
|
||||||
img = None
|
img = None
|
||||||
|
|||||||
Reference in New Issue
Block a user