-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
74 lines (64 loc) · 2.9 KB
/
app.py
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
'''
This bullshit frees medium articles for free!
'''
twitter_shit = {
'api_key': 'Consumer Keys / API Key',
'api_key_secret': 'Consumer Keys / API Secret',
'acc_token': 'Authentication Tokens / Access Token',
'acc_token_secret': 'Authentication Tokens / Access Secret',
}
from flask import *
app = Flask(__name__)
# Redirect / to /freer
@app.route('/', methods=['GET'])
def home_page():
return render_template('index.html')
# Renders a template
@app.route('/freer', methods=['GET'])
def free_this_article():
try:
wanted_url = request.args.to_dict()['wanted']
except:
return redirect('/', code=302)
if (is_url(wanted_url) and is_medium(wanted_url)):
res = freer_user.create_tweet(text=f'{hashlib.md5((str(random.randint(0, 9999)) + str(random.randint(9999, 99999999))).encode()).hexdigest()} \n {wanted_url}')
return render_template('article.html', url=res.data['text'].rsplit(' ')[-1])
else:
return render_template('error.html')
# Redirects automatically to the article
@app.route('/direct_freer', methods=['GET'])
def free_this_article_direct():
try:
wanted_url = request.args.to_dict()['wanted']
except:
return redirect('/', code=302)
if (is_url(wanted_url) and is_medium(wanted_url)):
res = freer_user.create_tweet(text=f'{hashlib.md5((str(random.randint(0, 9999)) + str(random.randint(9999, 99999999))).encode()).hexdigest()} \n {wanted_url}')
return redirect(res.data['text'].rsplit(' ')[-1], code=302)
else:
return 'What the fuck?'
# Check if the url is from Medium or not, Einstein's way
def is_medium(url):
if (url[0:8] != 'https://' and url[0:7] != 'http://'):
url = 'https://' + url
try:
url_html = requests.get(url).text
except:
return False
target = 'M588.67 296.36c0 163.67-131.78 296.35-294.33 296.35S0 460 0 296.36 131.78 0 294.34 0s294.33 132.69 294.33 296.36M911.56 296.36c0 154.06-65.89 279-147.17 279s-147.17-124.94-147.17-279 65.88-279 147.16-279 147.17 124.9 147.17 279M1043.63 296.36c0 138-23.17 249.94-51.76 249.94s-51.75-111.91-51.75-249.94 23.17-249.94 51.75-249.94 51.76 111.9 51.76 249.94'
if (url_html.find(target) >= 0 ):
return True
else:
return False
# Check if the user inputed url or some random string
def is_url(url: str):
if (validators.url(url)):
return True
elif (url[0:8] != 'https://' or url[0:7] != 'http://'):
url = 'https://' + url
return validators.url(url)
if __name__ == '__main__':
import tweepy, random, hashlib, validators, requests
freer_user = tweepy.Client(consumer_key=twitter_shit['api_key'], consumer_secret=twitter_shit['api_key_secret'], access_token=twitter_shit['acc_token'], access_token_secret=twitter_shit['acc_token_secret'])
# app.run(port=8000) # Uncomment if in production
app.run(port=5001, debug=True) # Comment if in production!