Spaces:
Runtime error
Runtime error
Commit
·
ff15b70
1
Parent(s):
fb4cf56
Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,14 @@ import streamlit as st
|
|
16 |
|
17 |
st.write("Hello world!")
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
GITHUB_PAT = os.environ['GITHUB']
|
20 |
api_key = os.environ['api_key']
|
21 |
secret_api_key = os.environ['secret_api_key']
|
@@ -31,84 +39,84 @@ secret_access_token = os.environ['secret_access_token']
|
|
31 |
|
32 |
|
33 |
|
34 |
-
import translators as ts
|
35 |
-
import translators.server as tss
|
36 |
-
import random
|
37 |
-
import tweepy
|
38 |
-
import time
|
39 |
-
import json
|
40 |
-
|
41 |
-
# works with tweets and replies too
|
42 |
-
|
43 |
-
def bulk_trans(text: str, ):
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
def check_or_write(filename:str, s1:str):
|
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 |
-
# from translator github
|
90 |
-
def auth(api_key,secret_api_key,access_token,secret_access_token):
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
auth(api_key,secret_api_key,access_token,secret_access_token)
|
112 |
|
113 |
|
114 |
|
|
|
16 |
|
17 |
st.write("Hello world!")
|
18 |
|
19 |
+
# Open the file in read mode
|
20 |
+
with open('tweet.txt', 'r') as f:
|
21 |
+
# Read the contents of the file into a string
|
22 |
+
text = f.read()
|
23 |
+
|
24 |
+
|
25 |
+
st.write(text)
|
26 |
+
|
27 |
GITHUB_PAT = os.environ['GITHUB']
|
28 |
api_key = os.environ['api_key']
|
29 |
secret_api_key = os.environ['secret_api_key']
|
|
|
39 |
|
40 |
|
41 |
|
42 |
+
# import translators as ts
|
43 |
+
# import translators.server as tss
|
44 |
+
# import random
|
45 |
+
# import tweepy
|
46 |
+
# import time
|
47 |
+
# import json
|
48 |
+
|
49 |
+
# # works with tweets and replies too
|
50 |
+
|
51 |
+
# def bulk_trans(text: str, ):
|
52 |
+
# """
|
53 |
+
# Will translate str into num_trans different languages and then back into original language
|
54 |
+
# :param text: str, must
|
55 |
+
# :return: str
|
56 |
+
# """
|
57 |
+
# curr = tss.google(text, to_language="en", sleep_seconds=0.051)
|
58 |
+
|
59 |
+
# return curr
|
60 |
+
|
61 |
+
# def check_or_write(filename:str, s1:str):
|
62 |
+
# """
|
63 |
+
# Will check if s1 is in a single line within filename and also write
|
64 |
+
# the tweet to filename if it is not inside. Returns true when s1 is
|
65 |
+
# not inside, returns false when s1 is found. Keeps line length of text
|
66 |
+
# file less than 22
|
67 |
+
# :param filename: str(must)
|
68 |
+
# :param s1: str(must)
|
69 |
+
# :return: bool
|
70 |
+
# """
|
71 |
+
# #checks to see if s1 is already inside
|
72 |
+
# with open(filename, 'r', encoding='utf8') as f1:
|
73 |
+
# f1.seek(0)
|
74 |
+
# lines=f1.readlines()
|
75 |
+
# l=0
|
76 |
+
# for line in lines:
|
77 |
+
# l+=1
|
78 |
+
# if s1 in line:
|
79 |
+
# return False
|
80 |
+
# #makes sure that there is not more than 20 lines in txt file
|
81 |
+
# if l>20:
|
82 |
+
# while l>20:
|
83 |
+
# del lines[0]
|
84 |
+
# l-=1
|
85 |
+
# new_file=open(filename, "w+", encoding='utf8')
|
86 |
+
# for line in lines:
|
87 |
+
# new_file.write(line)
|
88 |
+
# new_file.close()
|
89 |
+
|
90 |
+
# #returns true and also writes down text into file at the end
|
91 |
+
# with open(filename, 'a', encoding='utf8') as f1:
|
92 |
+
# f1.write(s1 + '\n')
|
93 |
+
# f1.close()
|
94 |
+
# return True
|
95 |
|
96 |
|
97 |
+
# # from translator github
|
98 |
+
# def auth(api_key,secret_api_key,access_token,secret_access_token):
|
99 |
+
# # Authenticate to Twitter
|
100 |
+
# auth = tweepy.OAuthHandler(api_key, secret_api_key)
|
101 |
+
# auth.set_access_token(access_token, secret_access_token)
|
102 |
+
# api = tweepy.API(auth, wait_on_rate_limit=True)
|
103 |
+
|
104 |
+
# #loops endlessly(60 sec interval) and checks,translates,and posts tweets
|
105 |
+
# # use this to get user id https://tweeterid.com/
|
106 |
+
# while True:
|
107 |
+
# # get twitter user_id at https://tweeterid.com/ by typing username
|
108 |
+
# timeline = api.user_timeline(user_id="1568348454619070465", #testing case using englishgiuly,
|
109 |
+
# #["2755544640", "1030481714", "407048032","227265199","190632194", "149542215","127854979", "106170617"],
|
110 |
+
# count=5, tweet_mode="extended",)
|
111 |
+
# for tweet in timeline:
|
112 |
+
# if check_or_write('tweet.txt', " ".join(tweet.full_text.splitlines())):
|
113 |
+
# curr = bulk_trans(tweet.full_text)
|
114 |
+
# status = f"{curr[:254]} https://twitter.com/1/status/{tweet.id}" # each link is converted to 23 characters
|
115 |
+
# api.update_status(status) # doesn't matter what username we use
|
116 |
+
# print(tweet.full_text)
|
117 |
+
# time.sleep(60)
|
118 |
+
|
119 |
+
# auth(api_key,secret_api_key,access_token,secret_access_token)
|
120 |
|
121 |
|
122 |
|