Spaces:
Runtime error
Runtime error
| # # from git import Repo | |
| # import os | |
| # import streamlit as st | |
| # import dateutil | |
| # import datetime | |
| # import translators as ts | |
| # import translators.server as tss | |
| # import random | |
| # import tweepy | |
| # import time | |
| # import json | |
| # time_now = datetime.datetime.now() | |
| # last_minute = time_now - dateutil.relativedelta.relativedelta(minutes=1) | |
| # # 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) | |
| # # works with tweets and replies too | |
| # 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 = 1605089422533218304 # change this if error or restart | |
| # while True: | |
| # # Get the first 20 tweets on the home timeline | |
| # tweets = api.get_home_timeline(max_results=12, | |
| # exclude='retweets', | |
| # expansions="author_id", #since_id=latest_tweet_id | |
| # start_time=last_minute) | |
| # if tweets.data is not None: | |
| # latest_tweet_id = tweets.meta['newest_id'] | |
| # for tweet in tweets.data: | |
| # if tweet.author_id in users: | |
| # print(f"Latest Tweet ID:{tweet.id}") | |
| # print(f"Latest tweet: {tweet.text}") | |
| # try: | |
| # curr = tss.google(tweet.text, to_language='en', sleep_seconds=0.051) | |
| # status = f"{curr[:254]}" | |
| # api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}") | |
| # print(f"Tweet successfully sent: {status}") | |
| # except: | |
| # curr = tss.tencent(tweet.text, to_language='en', sleep_seconds=0.051) | |
| # status = f"{curr[:254]}" | |
| # api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}") | |
| # print(f"Tweet successfully sent: {status}") | |
| # else: | |
| # continue | |
| # print(tweet.text) | |
| # print("_______________________") | |
| # time.sleep(60) | |
| # translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token) | |