# 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)