tracinginsights commited on
Commit
cb276a3
·
1 Parent(s): b6fe3fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -70
app.py CHANGED
@@ -1,92 +1,92 @@
1
- # from git import Repo
2
- import os
3
- import streamlit as st
4
 
5
- # st.set_page_config(
6
- # page_title="TRACING INSIGHTS",
7
- # page_icon=None,
8
- # layout="wide",
9
- # #initial_sidebar_state="expanded",
10
- # # menu_items={
11
- # # 'Get Help': 'https://www.extremelycoolapp.com/help',
12
- # # 'Report a bug': "https://www.extremelycoolapp.com/bug",
13
- # # 'About': "# This is a header. This is an *extremely* cool app!"
14
- # # }
15
- # )
16
 
17
- st.write("Hello world!")
18
 
19
 
20
 
21
- GITHUB_PAT = os.environ['GITHUB']
22
- api_key = os.environ['api_key']
23
- secret_api_key = os.environ['secret_api_key']
24
- access_token = os.environ['access_token']
25
- secret_access_token = os.environ['secret_access_token']
26
- bearer_token = os.environ['bearer_token']
27
 
28
- # if not os.path.exists('repo_directory'):
29
- # Repo.clone_from(f'https://tracinginsights:{GITHUB_PAT}@github.com/TracingInsights/translator.git', 'repo_directory' )
30
 
31
- # from repo_directory import translator
32
- # translator.auth(api_key,secret_api_key,access_token,secret_access_token)
33
 
34
 
35
 
36
 
37
- import translators as ts
38
- import translators.server as tss
39
- import random
40
- import tweepy
41
- import time
42
- import json
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
49
- users = [1568348454619070465,2755544640, 1030481714, 407048032,227265199,190632194, 149542215,127854979, 106170617]
50
 
51
 
52
- api = tweepy.Client(bearer_token=bearer_token, consumer_key=api_key,
53
- consumer_secret=secret_api_key, access_token=access_token,
54
- access_token_secret=secret_access_token,wait_on_rate_limit=True
55
- )
56
 
57
- #loops endlessly(60 sec interval) and checks,translates,and posts tweets
58
- # use this to get user id https://tweeterid.com/
59
- latest_tweet_id = 1605089422533218304 # 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.google(tweet.text, to_language='en', sleep_seconds=0.051)
75
- status = f"{curr[:254]}"
76
- api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
77
- print(f"Tweet successfully sent: {status}")
78
- except:
79
- curr = tss.tencent(tweet.text, to_language='en', sleep_seconds=0.051)
80
- status = f"{curr[:254]}"
81
- api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
82
- print(f"Tweet successfully sent: {status}")
83
- else:
84
- continue
85
- print(tweet.text)
86
- print("_______________________")
87
- time.sleep(60)
88
-
89
- translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token)
90
 
91
 
92
 
 
1
+ # # from git import Repo
2
+ # import os
3
+ # import streamlit as st
4
 
5
+ # # st.set_page_config(
6
+ # # page_title="TRACING INSIGHTS",
7
+ # # page_icon=None,
8
+ # # layout="wide",
9
+ # # #initial_sidebar_state="expanded",
10
+ # # # menu_items={
11
+ # # # 'Get Help': 'https://www.extremelycoolapp.com/help',
12
+ # # # 'Report a bug': "https://www.extremelycoolapp.com/bug",
13
+ # # # 'About': "# This is a header. This is an *extremely* cool app!"
14
+ # # # }
15
+ # # )
16
 
17
+ # st.write("Hello world!")
18
 
19
 
20
 
21
+ # GITHUB_PAT = os.environ['GITHUB']
22
+ # api_key = os.environ['api_key']
23
+ # secret_api_key = os.environ['secret_api_key']
24
+ # access_token = os.environ['access_token']
25
+ # secret_access_token = os.environ['secret_access_token']
26
+ # bearer_token = os.environ['bearer_token']
27
 
28
+ # # if not os.path.exists('repo_directory'):
29
+ # # Repo.clone_from(f'https://tracinginsights:{GITHUB_PAT}@github.com/TracingInsights/translator.git', 'repo_directory' )
30
 
31
+ # # from repo_directory import translator
32
+ # # translator.auth(api_key,secret_api_key,access_token,secret_access_token)
33
 
34
 
35
 
36
 
37
+ # import translators as ts
38
+ # import translators.server as tss
39
+ # import random
40
+ # import tweepy
41
+ # import time
42
+ # import json
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
49
+ # users = [1568348454619070465,2755544640, 1030481714, 407048032,227265199,190632194, 149542215,127854979, 106170617]
50
 
51
 
52
+ # api = tweepy.Client(bearer_token=bearer_token, consumer_key=api_key,
53
+ # consumer_secret=secret_api_key, access_token=access_token,
54
+ # access_token_secret=secret_access_token,wait_on_rate_limit=True
55
+ # )
56
 
57
+ # #loops endlessly(60 sec interval) and checks,translates,and posts tweets
58
+ # # use this to get user id https://tweeterid.com/
59
+ # latest_tweet_id = 1605089422533218304 # 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.google(tweet.text, to_language='en', sleep_seconds=0.051)
75
+ # status = f"{curr[:254]}"
76
+ # api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
77
+ # print(f"Tweet successfully sent: {status}")
78
+ # except:
79
+ # curr = tss.tencent(tweet.text, to_language='en', sleep_seconds=0.051)
80
+ # status = f"{curr[:254]}"
81
+ # api.create_tweet(text=status, quote_tweet_id=f"{tweet.id}")
82
+ # print(f"Tweet successfully sent: {status}")
83
+ # else:
84
+ # continue
85
+ # print(tweet.text)
86
+ # print("_______________________")
87
+ # time.sleep(60)
88
+
89
+ # translate(bearer_token,api_key,secret_api_key,access_token,secret_access_token)
90
 
91
 
92