Skip to content

Commit 9d86646

Browse files
committed
add tinyurl for production bot
1 parent 5c43330 commit 9d86646

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/lib/CollectorBot/handler.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22

3+
import requests
34
import tweepy
45
from asgiref.sync import async_to_sync
56
from channels.layers import get_channel_layer
@@ -54,18 +55,19 @@ def handle_collection(cls, status):
5455

5556
thread_tweets_ids = Grabber.grab_thread_tweets_ids(id)
5657
if len(thread_tweets_ids) > 0:
57-
content = ['<div class="tw-block">'+thread.full_text+'</div>']
58+
content = [
59+
'<div class="tw-block">'+thread.full_text+'</div>']
5860
for tweet_id in thread_tweets_ids:
5961
tweet = cls.tweepy_client.get_status(
6062
tweet_id, tweet_mode='extended')
6163
if tweet.user.id != thread.user.id:
6264
break
6365
Cleaner.clean_tweet(tweet)
6466
content.append(
65-
'<div class="tw-block">' + tweet.full_text+'</div>')
67+
'<div class="tw-block">' + tweet.full_text +
68+
'</div>')
6669
content = ''.join(content)
6770

68-
6971
post = Post.objects.create(
7072
id=id, content=content, author_name=author_name,
7173
author_screen_name=author_screen_name,
@@ -103,12 +105,14 @@ def __add_post_to_user(cls, post, user_id):
103105
def __reply_to_status(cls, status, old=False):
104106
if settings.APP_ENV == "dev":
105107
if old:
106-
reply = f''' @{status.user.screen_name} 🧵 already saved locally '''
108+
reply = f''' @{status.user.screen_name} 🧵 already saved locally 🧵'''
107109
else:
108-
reply = f''' @{status.user.screen_name} 🧵 saved locally '''
110+
reply = f''' @{status.user.screen_name} 🧵 saved locally 🧵'''
109111
else:
110112
path = reverse('post', args=(status.in_reply_to_status_id,))
111-
reply = f''' @{status.user.screen_name} here your requested 🧵 {settings.APP_URL}{path} '''
113+
r = requests.get(
114+
f'https://tinyurl.com/api-create.php?source=create&url={settings.APP_URL}{path}')
115+
reply = f''' @{status.user.screen_name} 🧵 {r.text} 🧵 '''
112116

113117
cls.tweepy_client.update_status(
114118
status=reply, in_reply_to_status_id=status.id)

0 commit comments

Comments
 (0)