2022-09-12 01:31:09 -07:00
|
|
|
## Shared utility functions.
|
|
|
|
|
|
|
|
|
|
import os
|
2022-09-24 04:02:19 -07:00
|
|
|
import talent_lists
|
2022-09-12 01:31:09 -07:00
|
|
|
|
|
|
|
|
# returns system path to this project, which is
|
2022-09-20 15:34:38 -07:00
|
|
|
# up one level from this file's directory (src).
|
2022-09-12 01:31:09 -07:00
|
|
|
def get_project_dir():
|
|
|
|
|
return os.path.join(os.path.dirname(__file__), os.pardir)
|
|
|
|
|
|
|
|
|
|
# determine if tweet involves cross-company interaction
|
2022-09-24 04:02:19 -07:00
|
|
|
def is_cross_company(pair: tuple):
|
|
|
|
|
author_id, mentions = pair[0].author_id, pair[1]
|
|
|
|
|
|
|
|
|
|
for mention_id in mentions:
|
|
|
|
|
if author_id in talent_lists.niji_en:
|
|
|
|
|
if mention_id in talent_lists.holo_en:
|
|
|
|
|
return True
|
|
|
|
|
elif author_id in talent_lists.holo_en:
|
|
|
|
|
if mention_id in talent_lists.niji_en:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def tweet_id_to_url(id):
|
|
|
|
|
return f'https://twitter.com/twitter/status/{id}'
|
|
|
|
|
|
|
|
|
|
def print_tweet(pair: tuple):
|
|
|
|
|
tweet, mentions = pair
|
|
|
|
|
s = (
|
|
|
|
|
f'{tweet.id}: {tweet.created_at}: involves {mentions}\n'
|
|
|
|
|
f'{tweet.text}\n'
|
|
|
|
|
f'-----\n'
|
|
|
|
|
f'{tweet.entities}\n'
|
|
|
|
|
f'{tweet.referenced_tweets}\n'
|
|
|
|
|
f'================================================='
|
|
|
|
|
)
|
|
|
|
|
print(s)
|
2022-09-12 01:31:09 -07:00
|
|
|
|
|
|
|
|
def clamp(n, smallest, largest):
|
|
|
|
|
return max(smallest, min(n, largest))
|