Spaces:
Runtime error
Runtime error
Commit
·
11a8339
1
Parent(s):
449b7fd
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,16 +43,6 @@ import json
|
|
| 43 |
|
| 44 |
# works with tweets and replies too
|
| 45 |
|
| 46 |
-
def bulk_trans(text: str, ):
|
| 47 |
-
"""
|
| 48 |
-
Will translate str into num_trans different languages and then back into original language
|
| 49 |
-
:param text: str, must
|
| 50 |
-
:return: str
|
| 51 |
-
"""
|
| 52 |
-
curr = tss.google(text, to_language="en", sleep_seconds=0.051)
|
| 53 |
-
|
| 54 |
-
return curr
|
| 55 |
-
|
| 56 |
|
| 57 |
def translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token):
|
| 58 |
# update users when you want to include more accounts
|
|
@@ -69,20 +59,30 @@ def translate(bearer_token,api_key,secret_api_key,access_token,secret_access_tok
|
|
| 69 |
latest_tweet_id = "1604906630918705152" # change this if error or restart
|
| 70 |
while True:
|
| 71 |
# Get the first 20 tweets on the home timeline
|
| 72 |
-
tweets = api.get_home_timeline(max_results=
|
|
|
|
|
|
|
| 73 |
if tweets.data is not None:
|
| 74 |
latest_tweet_id = tweets.meta['newest_id']
|
| 75 |
for tweet in tweets.data:
|
| 76 |
-
if tweet.author_id in users:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
print(f"tweet
|
|
|
|
| 80 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
|
|
|
|
| 82 |
except:
|
| 83 |
continue
|
| 84 |
print(tweet.text)
|
| 85 |
-
|
|
|
|
| 86 |
|
| 87 |
translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token)
|
| 88 |
|
|
|
|
| 43 |
|
| 44 |
# works with tweets and replies too
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token):
|
| 48 |
# update users when you want to include more accounts
|
|
|
|
| 59 |
latest_tweet_id = "1604906630918705152" # change this if error or restart
|
| 60 |
while True:
|
| 61 |
# Get the first 20 tweets on the home timeline
|
| 62 |
+
tweets = api.get_home_timeline(max_results=12,
|
| 63 |
+
exclude='retweets',
|
| 64 |
+
expansions="author_id", since_id=latest_tweet_id)
|
| 65 |
if tweets.data is not None:
|
| 66 |
latest_tweet_id = tweets.meta['newest_id']
|
| 67 |
for tweet in tweets.data:
|
| 68 |
+
if tweet.author_id in users:
|
| 69 |
+
|
| 70 |
+
print(f"Latest Tweet ID:{tweet.id}")
|
| 71 |
+
print(f"Latest tweet: {tweet.text}")
|
| 72 |
+
|
| 73 |
try:
|
| 74 |
+
curr = tss.tencent(tweet.text, to_language='en', sleep_seconds=0.051)
|
| 75 |
+
status = f"{curr[:254]}"
|
| 76 |
+
if len(status) == 0:
|
| 77 |
+
curr = tss.google(tweet.text, to_language='en', sleep_seconds=0.051)
|
| 78 |
+
status = f"{curr[:254]}"
|
| 79 |
api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
|
| 80 |
+
print(f"Tweet successfully sent: {status}")
|
| 81 |
except:
|
| 82 |
continue
|
| 83 |
print(tweet.text)
|
| 84 |
+
print("_______________________")
|
| 85 |
+
time.sleep(60)
|
| 86 |
|
| 87 |
translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token)
|
| 88 |
|