Spaces:
Runtime error
Runtime error
File size: 3,066 Bytes
449b7fd 19d1256 449b7fd 19d1256 449b7fd 19d1256 c5cb1c8 |
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 |
# from git import Repo
import os
import streamlit as st
# st.set_page_config(
# page_title="TRACING INSIGHTS",
# page_icon=None,
# layout="wide",
# #initial_sidebar_state="expanded",
# # menu_items={
# # 'Get Help': 'https://www.extremelycoolapp.com/help',
# # 'Report a bug': "https://www.extremelycoolapp.com/bug",
# # 'About': "# This is a header. This is an *extremely* cool app!"
# # }
# )
st.write("Hello world!")
GITHUB_PAT = os.environ['GITHUB']
api_key = os.environ['api_key']
secret_api_key = os.environ['secret_api_key']
access_token = os.environ['access_token']
secret_access_token = os.environ['secret_access_token']
bearer_token = os.environ['bearer_token']
# if not os.path.exists('repo_directory'):
# Repo.clone_from(f'https://tracinginsights:{GITHUB_PAT}@github.com/TracingInsights/translator.git', 'repo_directory' )
# from repo_directory import translator
# translator.auth(api_key,secret_api_key,access_token,secret_access_token)
import translators as ts
import translators.server as tss
import random
import tweepy
import time
import json
# works with tweets and replies too
def bulk_trans(text: str, ):
"""
Will translate str into num_trans different languages and then back into original language
:param text: str, must
:return: str
"""
curr = tss.google(text, to_language="en", sleep_seconds=0.051)
return curr
def translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token):
# update users when you want to include more accounts
users = ["1568348454619070465","2755544640", "1030481714", "407048032","227265199","190632194", "149542215","127854979", "106170617"]
api = tweepy.Client(bearer_token=bearer_token, consumer_key=api_key,
consumer_secret=secret_api_key, access_token=access_token,
access_token_secret=secret_access_token,wait_on_rate_limit=True
)
#loops endlessly(60 sec interval) and checks,translates,and posts tweets
# use this to get user id https://tweeterid.com/
latest_tweet_id = "1604906630918705152" # change this if error or restart
while True:
# Get the first 20 tweets on the home timeline
tweets = api.get_home_timeline(max_results=30,exclude='retweets',expansions="author_id", since_id=latest_tweet_id)
if tweets.data is not None:
latest_tweet_id = tweets.meta['newest_id']
for tweet in tweets.data:
if tweet.author_id in users:
curr = bulk_trans(tweet.text)
status = f"{curr[:254]}"
print(f"tweet id is {tweet.id}")
try:
api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
except:
continue
print(tweet.text)
time.sleep(60)
translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token)
|