add dry run, handling of None names (#7)
This commit is contained in:
+1
-1
@@ -144,7 +144,7 @@ async def run(PROGRAM_ARGS):
|
|||||||
print(f"Invalid tweet {id}!")
|
print(f"Invalid tweet {id}!")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
posted = await TwAPI.instance.post_ttweet_by_id(i)
|
posted = await TwAPI.instance.post_ttweet_by_id(i, PROGRAM_ARGS.dry_run)
|
||||||
if posted:
|
if posted:
|
||||||
queue.add_finished_tweet(i)
|
queue.add_finished_tweet(i)
|
||||||
print("Successfully posted tweet. Sleeping for 5 minutes")
|
print("Successfully posted tweet. Sleeping for 5 minutes")
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ def init_argparse():
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Go through queue first before attempting to pull tweets.",
|
help="Go through queue first before attempting to pull tweets.",
|
||||||
)
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--dry-run",
|
||||||
|
action="store_true",
|
||||||
|
help="Don't actually post anything to Twitter; use to check outputs from console.",
|
||||||
|
)
|
||||||
p.add_argument(
|
p.add_argument(
|
||||||
"--post-id",
|
"--post-id",
|
||||||
action="append",
|
action="append",
|
||||||
|
|||||||
+3
-3
@@ -278,7 +278,7 @@ class TalentTweet:
|
|||||||
rt_username = (
|
rt_username = (
|
||||||
util.get_username_with_company(self.rt_author_id)
|
util.get_username_with_company(self.rt_author_id)
|
||||||
if self.rt_author_id != -1
|
if self.rt_author_id != -1
|
||||||
else None
|
else "someone"
|
||||||
)
|
)
|
||||||
if rt_username == author_username:
|
if rt_username == author_username:
|
||||||
rt_username = "themselves"
|
rt_username = "themselves"
|
||||||
@@ -291,7 +291,7 @@ class TalentTweet:
|
|||||||
reply_username = (
|
reply_username = (
|
||||||
util.get_username_with_company(self.reply_to)
|
util.get_username_with_company(self.reply_to)
|
||||||
if self.reply_to != -1
|
if self.reply_to != -1
|
||||||
else None
|
else "someone"
|
||||||
)
|
)
|
||||||
if reply_username == author_username:
|
if reply_username == author_username:
|
||||||
reply_username = "themselves"
|
reply_username = "themselves"
|
||||||
@@ -303,7 +303,7 @@ class TalentTweet:
|
|||||||
quoted_username = (
|
quoted_username = (
|
||||||
util.get_username_with_company(self.quote_tweeted)
|
util.get_username_with_company(self.quote_tweeted)
|
||||||
if self.quote_tweeted != -1
|
if self.quote_tweeted != -1
|
||||||
else None
|
else "someone"
|
||||||
)
|
)
|
||||||
if quoted_username == author_username:
|
if quoted_username == author_username:
|
||||||
quoted_username = "themselves"
|
quoted_username = "themselves"
|
||||||
|
|||||||
+5
-5
@@ -136,6 +136,8 @@ class TwAPI:
|
|||||||
# return True = successfully posted a single ttweet
|
# return True = successfully posted a single ttweet
|
||||||
# return False = did not post ttweet (duplicate)
|
# return False = did not post ttweet (duplicate)
|
||||||
async def post_ttweet(self, ttweet: tt.TalentTweet, dry_run=False):
|
async def post_ttweet(self, ttweet: tt.TalentTweet, dry_run=False):
|
||||||
|
import main
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"------{ttweet.tweet_id} ({util.get_username_local(ttweet.author_id)})------"
|
f"------{ttweet.tweet_id} ({util.get_username_local(ttweet.author_id)})------"
|
||||||
)
|
)
|
||||||
@@ -145,11 +147,9 @@ class TwAPI:
|
|||||||
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print("-------------------- DRY RUN --------------------")
|
print("-------------------- DRY RUN --------------------")
|
||||||
print(ttweet)
|
print(ttweet)
|
||||||
if dry_run:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# NO DRY-RUN: actually post tweet
|
|
||||||
# main tweet: text + screenshot
|
# main tweet: text + screenshot
|
||||||
try:
|
try:
|
||||||
print("creating main QRT w/ screenshot...")
|
print("creating main QRT w/ screenshot...")
|
||||||
@@ -188,7 +188,7 @@ class TwAPI:
|
|||||||
raise e
|
raise e
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def post_ttweet_by_id(self, id: int):
|
async def post_ttweet_by_id(self, id: int, dry_run=False):
|
||||||
from scraper import Scraper
|
from scraper import Scraper
|
||||||
|
|
||||||
print(f"Manually posting tweet {id}")
|
print(f"Manually posting tweet {id}")
|
||||||
@@ -204,4 +204,4 @@ class TwAPI:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
print(f"Posting {ttweet.username}/{ttweet.tweet_id}...")
|
print(f"Posting {ttweet.username}/{ttweet.tweet_id}...")
|
||||||
return await self.post_ttweet(ttweet)
|
return await self.post_ttweet(ttweet, dry_run)
|
||||||
|
|||||||
Reference in New Issue
Block a user