-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
89 lines (41 loc) · 1.71 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
from flask import Flask, render_template, request
from urllib.request import urlopen
import json
import time
import smtplib
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/data', methods=["GET","POST"])
def data():
if request.method == "POST":
f = request.form.get('name')
mail = request.form.get('mail')
price_target = float(request.form.get('profit'))
loss_target = float(request.form.get('loss'))
while(1):
url = urlopen(f"https://api.nomics.com/v1/currencies/ticker?key=1e0c0c160bc402daf0da9293ca1f7e1c2c6a3022&ids={str(f).upper()}")
req = url.read().decode('utf-8')
load = json.loads(req)
price = float(load[0]["price"])
print(price)
time.sleep(2)
if price > price_target:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("[email protected]", "mmwzcribduqqxnea")
message = (f"its time to sell your coin \ncurrent price is:{price}")
s.sendmail("[email protected]", mail, message)
s.quit()
return("MAIL SENT")
elif price < loss_target:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("[email protected]", "mmwzcribduqqxnea")
message = (f"its time to buy your coin\ncurrent price is:{price}")
s.sendmail("[email protected]", mail, message)
s.quit()
return("MAIL SENT")
if __name__ == '__main__':
app.run()