This repository was archived by the owner on Aug 7, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtl_tweets.py
More file actions
executable file
·659 lines (584 loc) · 23.1 KB
/
Copy pathtl_tweets.py
File metadata and controls
executable file
·659 lines (584 loc) · 23.1 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
#!/usr/bin/env python
# encoding: utf-8
"""
tl_tweets.py
Copyright (c) 2015 Rob Mason
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Twitter: @Teslaliving
Blog: http://teslaliving.net
Description:
Twitter Helper Functions
Dependencies:
twython: https://github.com/ryanmcgrath/twython (most twython things no longer work as of APIv2)
tweepy: https://github.com/tweepy/tweepy
You need to get application keys for Twitter at https://apps.twitter.com
Provide them via environment variables:
TL_APP_KEY
TL_APP_SECRET
TL_OAUTH_TOKEN
TL_OAUTH_TOKEN_SECRET
TL_BEARER_TOKEN
Or via init function.
Note: The logging stuff is as Twython emits a bunch of stuff during its work that I wanted to suppress
NOTE: ONLY tweet_string HAS BEEN TESTING/IS WORKING WITH TWITTER API 2.0
"""
import os
import sys
import argparse
import glob
import time
import random
import logging
from twython import Twython, TwythonAuthError
import tweepy
basepath = os.path.dirname(sys.argv[0])
sys.path.append(os.path.join(basepath, 'twython'))
# Initialize Twitter Keys
APP_KEY = None
APP_SECRET = None
OAUTH_TOKEN = None
OAUTH_TOKEN_SECRET = None
BEARER_TOKEN = None
# Cache self ID
MYSELF = None
if 'TL_APP_KEY' in os.environ:
APP_KEY = os.environ['TL_APP_KEY']
if 'TL_APP_SECRET' in os.environ:
APP_SECRET = os.environ['TL_APP_SECRET']
if 'TL_OAUTH_TOKEN' in os.environ:
OAUTH_TOKEN = os.environ['TL_OAUTH_TOKEN']
if 'TL_OAUTH_TOKEN_SECRET' in os.environ:
OAUTH_TOKEN_SECRET = os.environ['TL_OAUTH_TOKEN_SECRET']
if 'TL_BEARER_TOKEN' in os.environ:
BEARER_TOKEN = os.environ['TL_BEARER_TOKEN']
def init_twitter_account(app_key, app_secret, oauth_token, oauth_token_secret, bearer_token=None):
global APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET, BEARER_TOKEN, MYSELF
APP_KEY = app_key
APP_SECRET = app_secret
OAUTH_TOKEN = oauth_token
OAUTH_TOKEN_SECRET = oauth_token_secret
BEARER_TOKEN = bearer_token
MYSELF = None
def check_twitter_config():
if not APP_KEY:
raise Exception("APP_KEY missing for twitter")
if not APP_SECRET:
raise Exception("APP_KEY missing for twitter")
if not OAUTH_TOKEN:
raise Exception("OAUTH_TOKEN missing for twitter")
if not OAUTH_TOKEN_SECRET:
raise Exception("OAUTH_TOKEN_SECRET missing for twitter")
if not BEARER_TOKEN:
raise Exception("BEARER_TOKEN missing for twitter")
def twitter_auth_issue(e):
message = "There was a problem with automated tweet operations.\n\n"
message += "\nPlease investigate."
print(message, file=sys.stderr)
def is_transient_twitter_error(e):
"""Check if a Twitter API error is transient and should be retried."""
error_str = str(e)
transient_patterns = [
'timeout', 'timed out', 'TimeoutError',
'Connection aborted', 'ConnectionError', 'Connection refused',
'502', 'Bad Gateway',
'503', 'Service Unavailable',
'504', 'Gateway Timeout',
'408', 'Request Timeout',
'Failed to send request',
'write operation timed out'
]
return any(pattern.lower() in error_str.lower() for pattern in transient_patterns)
def tweet_string(message, log, media=None):
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
api = tweepy.Client(
bearer_token=BEARER_TOKEN,
access_token=OAUTH_TOKEN,
access_token_secret=OAUTH_TOKEN_SECRET,
consumer_key=APP_KEY,
consumer_secret=APP_SECRET
)
max_retries = 3
base_sleep = 5
for attempt in range(max_retries):
try:
uploaded_media = None
if media:
auth = tweepy.OAuth1UserHandler(
APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET
)
oldapi = tweepy.API(auth)
uploaded_media = oldapi.media_upload(filename=media)
log.setLevel(logging.ERROR)
if uploaded_media:
api.create_tweet(
text=message,
media_ids=[uploaded_media.media_id]
)
else:
api.create_tweet(
text=message
)
log.setLevel(old_level)
log.info("Tweet posted successfully")
return
except Exception as e:
log.setLevel(old_level)
# Check if this is a transient error
if is_transient_twitter_error(e):
if attempt < max_retries - 1:
sleep_time = base_sleep * (2 ** attempt)
log.warning("Transient Twitter error (attempt %d/%d): %s",
attempt + 1, max_retries, str(e)[:200])
log.info("Retrying in %d seconds...", sleep_time)
time.sleep(sleep_time)
else:
# Max retries reached
log.error("Max retries reached for transient Twitter error: %s", str(e)[:200])
log.exception("Failed to tweet after %d attempts", max_retries)
raise
else:
# Non-transient error - don't retry
log.error("Non-transient Twitter error: %s", str(e)[:200])
log.exception("Problem trying to tweet string")
twitter_auth_issue(e)
raise
def tweet_price(price, log, stock, extra="", image=None):
log.debug("Tweet about stock price for %s: $%s", stock, price)
message = "$%s current stock price: $%s. %s" % (stock, price, extra)
tweet_string(message=message, log=log, media=image)
def tweet_search(log, item, limit=50, since_id=None):
log.debug("Searching twitter for '%s'", item)
check_twitter_config()
if len(item) > 500:
log.error(" Search string too long")
raise Exception("Search string too long: %d", len(item))
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
result = twitter.search(q=item, count=limit, since_id=since_id)
except TwythonAuthError as e:
log.setLevel(old_level)
twitter_auth_issue(e)
raise
except Exception:
log.setLevel(old_level)
raise
log.setLevel(old_level)
return result
def check_relationship(log, id):
my_screen_name = get_screen_name(log)
if my_screen_name == "Unknown":
raise ValueError("Couldn't get my own screen name")
log.debug("Checking relationship of %s with me (%s)", id, my_screen_name)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
result = twitter.show_friendship(source_screen_name=my_screen_name, target_screen_name=id)
except TwythonAuthError as e:
log.setLevel(old_level)
log.exception(" Problem trying to check relationship")
twitter_auth_issue(e)
raise
log.setLevel(old_level)
return result["relationship"]["source"]["following"], result["relationship"]["source"]["followed_by"]
def follow_twitter_user(log, id):
log.debug("Following %s", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
twitter.create_friendship(screen_name=id)
except TwythonAuthError as e:
log.setLevel(old_level)
log.exception(" Problem trying to follow twitter user")
twitter_auth_issue(e)
raise
except Exception as e:
log.setLevel(old_level)
log.exception("Error following %s", id)
twitter_auth_issue(e)
raise
log.setLevel(old_level)
def unfollow_twitter_user(log, id):
log.debug("Unfollowing %s", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
twitter.destroy_friendship(screen_name=id)
except TwythonAuthError as e:
log.setLevel(old_level)
log.exception("Error unfollowing %s", id)
twitter_auth_issue(e)
raise
except Exception as e:
log.exception("Error unfollowing %s", id)
twitter_auth_issue(e)
raise
log.setLevel(old_level)
def get_account_details(log, id):
log.debug("Getting account details for %s", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
api = tweepy.Client(
bearer_token=BEARER_TOKEN,
access_token=OAUTH_TOKEN,
access_token_secret=OAUTH_TOKEN_SECRET,
consumer_key=APP_KEY,
consumer_secret=APP_SECRET
)
try:
user = api.get_user(username=id, user_fields=['public_metrics', 'verified', 'description'])
details = {
'screen_name': user.data.username,
'name': user.data.name,
'description': getattr(user.data, 'description', None),
'verified': getattr(user.data, 'verified', None),
'followers_count': user.data.public_metrics.get('followers_count', 0),
'friends_count': user.data.public_metrics.get('following_count', 0),
'statuses_count': user.data.public_metrics.get('tweet_count', 0),
'id': user.data.id
}
except tweepy.NotFound:
log.setLevel(old_level)
details = None
except Exception as e:
log.setLevel(old_level)
raise e
log.setLevel(old_level)
return details
def get_self_details(log):
log.debug("Getting authenticated user details")
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
api = tweepy.Client(
bearer_token=BEARER_TOKEN,
access_token=OAUTH_TOKEN,
access_token_secret=OAUTH_TOKEN_SECRET,
consumer_key=APP_KEY,
consumer_secret=APP_SECRET
)
try:
user = api.get_me(user_fields=['public_metrics', 'verified', 'description'])
details = {
'screen_name': user.data.username,
'name': user.data.name,
'description': getattr(user.data, 'description', None),
'verified': getattr(user.data, 'verified', None),
'followers_count': user.data.public_metrics.get('followers_count', 0),
'friends_count': user.data.public_metrics.get('following_count', 0),
'statuses_count': user.data.public_metrics.get('tweet_count', 0),
'id': user.data.id
}
except Exception as e:
log.setLevel(old_level)
raise e
log.setLevel(old_level)
return details
def get_follower_count(log, id):
log.debug("Getting follower count for %s", id)
details = get_account_details(log, id)
if details:
log.debug("%d", details["followers_count"])
return details["followers_count"]
else:
return None
def get_screen_name(log):
global MYSELF
if not MYSELF or MYSELF == "Unknown":
log.debug("Getting current user screen name")
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
details = twitter.verify_credentials()
except TwythonAuthError as e:
log.setLevel(old_level)
log.exception(" Problem trying to get screen name")
twitter_auth_issue(e)
raise
except Exception as e:
log.exception(" Problem trying to get screen name")
twitter_auth_issue(e)
details = None
log.setLevel(old_level)
name = "Unknown"
if details:
name = details["screen_name"]
MYSELF = name
return MYSELF
def get_following(log, id):
log.debug("Getting people %s is following", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
log.setLevel(old_level)
cursor = -1
max_loops = 15
while cursor != 0:
try:
log.setLevel(logging.ERROR)
following = twitter.get_friends_list(screen_name=id, cursor=cursor, count=200)
log.setLevel(old_level)
except TwythonAuthError as e:
log.exception(" Problem trying to get people following")
twitter_auth_issue(e)
raise
except Exception as e:
log.setLevel(old_level)
log.exception(" Problem trying to get people following")
twitter_auth_issue(e)
raise
for u in following["users"]:
yield u["screen_name"]
cursor = following["next_cursor"]
if cursor:
s = random.randint(55, 65)
log.debug("Sleeping %ds to avoid rate limit. Cursor: %s", s, cursor)
time.sleep(s)
else:
log.debug("Normal query end")
max_loops -= 1
if max_loops <= 0:
log.debug("Killing search due to max loops")
break
log.setLevel(old_level)
def get_followers(log, id):
log.debug("Getting people following %s", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
api = tweepy.Client(
bearer_token=BEARER_TOKEN,
access_token=OAUTH_TOKEN,
access_token_secret=OAUTH_TOKEN_SECRET,
consumer_key=APP_KEY,
consumer_secret=APP_SECRET
)
log.setLevel(old_level)
try:
user = api.get_user(username=id)
user_id = user.data.id
except Exception as e:
log.setLevel(old_level)
log.exception("Problem getting user %s", id)
twitter_auth_issue(e)
raise
pagination_token = None
max_loops = 15
while True:
try:
log.setLevel(logging.ERROR)
response = api.get_users_followers(id=user_id, max_results=1000, pagination_token=pagination_token)
log.setLevel(old_level)
except Exception as e:
log.setLevel(old_level)
log.exception("Problem getting followers for %s", id)
twitter_auth_issue(e)
raise
if response.data:
for u in response.data:
yield {'screen_name': u.username}
if response.meta and 'next_token' in response.meta:
pagination_token = response.meta['next_token']
else:
log.debug("Pagination end")
break
max_loops -= 1
if max_loops <= 0:
log.debug("Killing search due to max loops")
break
log.setLevel(old_level)
def favorite_tweet(log, id):
log.debug("Favoriting tweet % s", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
log.setLevel(old_level)
try:
log.setLevel(logging.ERROR)
res = twitter.create_favorite(id=id)
log.setLevel(old_level)
return res
except TwythonAuthError as e:
log.setLevel(old_level)
if 'You have already favorited this status' in str(e):
log.info("tweet already favorited")
else:
log.exception("Problem trying to favorite tweet")
twitter_auth_issue(e)
raise
def retweet_tweet(log, id):
log.debug("Retweeting tweet % s", id)
check_twitter_config()
logging.captureWarnings(True)
old_level = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
log.setLevel(old_level)
try:
log.setLevel(logging.ERROR)
res = twitter.retweet(id=id)
log.setLevel(old_level)
return res
except TwythonAuthError as e:
log.setLevel(old_level)
if 'You have already retweeted this status' in str(e):
log.info("tweet already retweeted")
else:
log.exception("Problem trying to retweeted tweet")
twitter_auth_issue(e)
raise
def main():
parser = argparse.ArgumentParser(description='Tweet testing')
parser.add_argument('--pic', help='Tweet a picture', required=False, action='store_true')
parser.add_argument('--followers', help='Get list of followers for a username', required=False)
parser.add_argument('--user', help='Get user details for a username', required=False)
parser.add_argument('--me', help='Get details for the authenticated user', required=False, action='store_true')
parser.add_argument('--following', help='Get list of users followed by a username', required=False)
parser.add_argument('--follow', help='Follow a user', required=False)
parser.add_argument('--unfollow', help='Unfollow a user', required=False)
parser.add_argument('--like', help='Like a tweet by ID', required=False)
parser.add_argument('--retweet', help='Retweet a tweet by ID', required=False)
parser.add_argument('--relationship', help='Check relationship with a user', required=False)
parser.add_argument('--screenname', help='Get my screen name', required=False, action='store_true')
parser.add_argument('--follower-count', help='Get follower count for a username', required=False)
parser.add_argument('--search', help='Search tweets', required=False)
args = parser.parse_args()
log = logging.getLogger(__name__)
if args.followers:
try:
for user in get_followers(log, args.followers):
print(user['screen_name'])
except Exception as e:
print(f"Error getting followers: {e}", file=sys.stderr)
elif args.user:
try:
details = get_account_details(log, args.user)
if details:
print(f"Username: {details.get('screen_name', 'N/A')}")
print(f"Name: {details.get('name', 'N/A')}")
print(f"Description: {details.get('description', 'N/A')}")
print(f"Verified: {details.get('verified', 'Unknown')}")
print(f"Followers: {details.get('followers_count', 'N/A')}")
print(f"Following: {details.get('friends_count', 'N/A')}")
print(f"Tweets: {details.get('statuses_count', 'N/A')}")
else:
print("User not found", file=sys.stderr)
except Exception as e:
print(f"Error getting user: {e}", file=sys.stderr)
elif args.me:
try:
details = get_self_details(log)
print(f"Username: {details.get('screen_name', 'N/A')}")
print(f"Name: {details.get('name', 'N/A')}")
print(f"Description: {details.get('description', 'N/A')}")
print(f"Verified: {details.get('verified', 'Unknown')}")
print(f"Followers: {details.get('followers_count', 'N/A')}")
print(f"Following: {details.get('friends_count', 'N/A')}")
print(f"Tweets: {details.get('statuses_count', 'N/A')}")
except Exception as e:
print(f"Error getting authenticated user: {e}", file=sys.stderr)
elif args.following:
try:
for screen_name in get_following(log, args.following):
print(screen_name)
except Exception as e:
print(f"Error getting following: {e}", file=sys.stderr)
elif args.follow:
try:
follow_twitter_user(log, args.follow)
print("Followed")
except Exception as e:
print(f"Error following user: {e}", file=sys.stderr)
elif args.unfollow:
try:
unfollow_twitter_user(log, args.unfollow)
print("Unfollowed")
except Exception as e:
print(f"Error unfollowing user: {e}", file=sys.stderr)
elif args.like:
try:
favorite_tweet(log, args.like)
print("Liked")
except Exception as e:
print(f"Error liking tweet: {e}", file=sys.stderr)
elif args.retweet:
try:
retweet_tweet(log, args.retweet)
print("Retweeted")
except Exception as e:
print(f"Error retweeting tweet: {e}", file=sys.stderr)
elif args.relationship:
try:
following, followed_by = check_relationship(log, args.relationship)
print(f"You are following {args.relationship}: {following}")
print(f"{args.relationship} is following you: {followed_by}")
except Exception as e:
print(f"Error checking relationship: {e}", file=sys.stderr)
elif args.screenname:
try:
screen_name = get_screen_name(log)
print(f"Your screen name: {screen_name}")
except Exception as e:
print(f"Error getting screen name: {e}", file=sys.stderr)
elif args.follower_count:
try:
count = get_follower_count(log, args.follower_count)
if count is not None:
print(f"Followers: {count}")
else:
print("User not found", file=sys.stderr)
except Exception as e:
print(f"Error getting follower count: {e}", file=sys.stderr)
elif args.search:
try:
result = tweet_search(log, args.search, limit=10)
if 'statuses' in result and result['statuses']:
for i, status in enumerate(result['statuses'][:5]):
print(f"{i+1}. {status.get('text', '')[:140]}...")
else:
print("No results")
except Exception as e:
print(f"Error searching tweets: {e}", file=sys.stderr)
elif args.pic:
pic = random.choice(glob.glob('images/*.jpg'))
message = "One of my favorite pictures"
print(f"Tweeting: '{message}' with pic: {pic}")
tweet_string(message=message, log=log, media=pic)
else:
parser.print_help()
if __name__ == '__main__':
main()