From bde07333cc38b14af5d1aca3c1b2b8dbc83e63e7 Mon Sep 17 00:00:00 2001 From: "Irsa Mughal (mughali4)" Date: Sat, 15 Apr 2023 15:57:28 +0100 Subject: [PATCH] Add files via upload --- __pycache__/views.cpython-311.pyc | Bin 0 -> 3322 bytes app.py | 10 ++++ func.py | 52 ++++++++++++++++++ main.py | 60 +++++++++++++++++++++ requirements.txt | 2 + static/index.js | 1 + templates/form.html | 4 ++ templates/index.html | 21 ++++++++ templates/login.html | 23 ++++++++ templates/trackpage.html | 7 +++ views.py | 85 ++++++++++++++++++++++++++++++ 11 files changed, 265 insertions(+) create mode 100644 __pycache__/views.cpython-311.pyc create mode 100644 app.py create mode 100644 func.py create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 static/index.js create mode 100644 templates/form.html create mode 100644 templates/index.html create mode 100644 templates/login.html create mode 100644 templates/trackpage.html create mode 100644 views.py diff --git a/__pycache__/views.cpython-311.pyc b/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..79f80c462c17f88f73f94ac97df4a9f5fb5ccce5 GIT binary patch literal 3322 zcmbtW&2JmW6`%d$F1Zvbij*o_HOxk?B|0i;vy!4XN(q8ldGrk$sj`iWStI4?U(2O;t<+G7-6o6bS}r~e2&+J zoS=(2QI~R(9>@iBIVW>Whc7BQg-3)VK`iX>2t9_@qFe~%G70X$e2<~Er78(+hdaIf zPb~IoV(AXr0fon1rQFbgwt+rddB8Supsmtp8yv8W9%vitvsDLdhy5tUaxomvjT|`7 z5RTyJD*t4-H-ErKE%j z&09n-7d4A`a)lQ2*9__@l;8p-E0!nUFpW~-+PWuG^1BK#El)aE)XcR@o^-Q7ZkaE* z%u4sn;6-S+=Sg_kLRL2y5ad{I{J<;zQZ-ZnA3jN6xAfu{92LRp3-lZ~dU5K^>E$aX zq2_Xdnwq}+j&ZA0G&F23TU1+FBeeVUJxQ0>J@LAs6B+|+$arLq0IQ+@1WjIkByFfdPUuR`O{I}EMkROnSsNf{RI z9*)pxdDv-5S8$nva-tr)Rv2qL^o~Z_y^g!Un2B2aAkbY=t(l{w8O! z9BLq#vG(FKGpIFr&T(_+9=}bl| z7t)2YX#tR=R}4K<4gXwQSs|vGUnA>pS7n;KsR2-W!J<)GEm##yJOwb)f2&6PtSD=% z#4r4mKv})eNw$o#Vw5aWvaD(lkW_CegeZ%v7ieXUC$bSwfRz~1`mkzx0u-PpwUAkE zPvVJwMY7GN0v=x|djdeT$I+Jy(qk}avgAnm)PkL`zRrML&zB9;q9XrXIcKL}nh{b|PSXlEB${agDSA3bs9bGD5X%m%xXmtw< z%5`6H;=T`-ew?#Z*g%`Gyn&u5y@d%$9Bd^q9R)Q{(y(4Ac}iI`&07Y=)#LA$AX^JK zc?Rxn$i0GAG}FoVi$pU?(xU50ZB;9j(*DI*4f&C5U$~w`C^cv*;3p{kF-%X7GsY6C zg|saB=qxak1vJ^pFUg;T&V%GvY={7>p=aUY+SxrhvM;yPk-LkHkgHB^-+HR1Z8iOm zslU&BS#`4)zg~Tsy<%st>?RiLXX|IbjZb`be*4^CFF(BO#An?2j2)iYQx7*5A60C1 z&Qa%FbKt z^IWQlfc;xQ{76@l?C9kjZrtU@o4m;MfHA#8T}h;)_Zx>Bb-B?d&v8F(B4A8!tSeDE zdLKI+SRZ0~uQR>Zncm^9B!ReaO=UlDRZi{q_@nK>cBOH') +# def delivery(tracking_number): +# delivery = Delivery.query.filter_by(tracking_number=tracking_number).first_or_404() +# return render_template('delivery.html', delivery=delivery) +# updateStatus(trackingNumber) { +# $.ajax({ +# type: "POST", +# url: "/update_status", +# data: { tracking_number: trackingNumber }, +# success: function(data) { +# // update the delivery status on the web page +# } +# }); +# } +# @app.route('/update_status', methods=['POST']) +# def update_status(): +# tracking_number = request.form['tracking_number'] +# delivery = Delivery.query.filter_by(tracking_number=tracking_number).first() +# if delivery: +# delivery.status = 'Delivered' +# db.session.commit() +# return 'Delivery status updated.' +# else: +# return 'Delivery not found.' + diff --git a/main.py b/main.py new file mode 100644 index 0000000..354b9bb --- /dev/null +++ b/main.py @@ -0,0 +1,60 @@ +# import phonenumbers +from app import number +#import folium +# number="+447878066443" + +from phonenumbers import geocoder +ch_number = phonenumbers.parse(number,"CH") +print(geocoder.description_for_number(ch_number,"en")) + +location = geocoder.description_for_number(ch_number,"en") + +import opencage +from opencage.geocoder import OpenCageGeocode +key = '831700a26df246a49d2fd85e9859e1ae' +geocoder =OpenCageGeocode(key) +query = str(location) +results = geocoder.geocode(query) +# print(results) +lat =results[0]['geometry']['lat'] +lng =results[0]['geometry']['lng'] +print(lat,lng) + +mymap = folium.Map(location=[lat,lng], zoom_start= 9) +folium.Marker([lat,lng], popup=location).add_to(mymap) +mymap.save("mylocation.html") + + +# --------------- +# stackify website +# IPSTack key +# https://stackify.com/python-geocoder-a-guide-to-managing-locations-in-your-apps/ +#---------------- +import requests +key = "e88e972426c5be7ed2b8a1a45b4460dd" +ip = "2.216.185.49" +url = "http://api.ipstack.com/" + ip +"?access_key=" + key +response = requests.get(url).json() +print(response) + +def lng_lat_from_ip(ip): + url = "http://api.ipstack.com/" + ip + "?access_key=" + key + response = requests.get(url).json() + return (response['longitude'], response['latitude']) +longitude, latitude = lng_lat_from_ip(ip) + + + +# from geopy.distance import geodesic +# Brighton = (longitude, latitude) # I used our function above to get this. +# cleveland_oh = (41.499498, -81.695391) # I looked this one up. +# print("distance " ,geodesic(Brighton, cleveland_oh).miles) + + +from flask import Flask, render_template + +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('index.html') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6f42ae1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +requests \ No newline at end of file diff --git a/static/index.js b/static/index.js new file mode 100644 index 0000000..3cfcd9f --- /dev/null +++ b/static/index.js @@ -0,0 +1 @@ +console.log("i am running"); \ No newline at end of file diff --git a/templates/form.html b/templates/form.html new file mode 100644 index 0000000..184d617 --- /dev/null +++ b/templates/form.html @@ -0,0 +1,4 @@ +
+

enter IP

+ +
\ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..a4ed215 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,21 @@ + + + + + + + FlaskBlog + + + + + {% block content %} +

hello

+ +

Welcome to TRacking website

+

{{name}}

+

Track IP

+ {% endblock %} + + + \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..a01012d --- /dev/null +++ b/templates/login.html @@ -0,0 +1,23 @@ + + + Flask Intro - login page + + + + +
+

Please login

+
+
+ + + +
+ {% if error %} +

Error: {{ error }} + {% endif %} +

+ + \ No newline at end of file diff --git a/templates/trackpage.html b/templates/trackpage.html new file mode 100644 index 0000000..95f598e --- /dev/null +++ b/templates/trackpage.html @@ -0,0 +1,7 @@ +{% extends "index.html" %} +{% block content %} +

Here are your coordiantes

+

longitude : {{longitude}}

+

latitude : {{latitude}}

+

content : {{contentt}}

+{% endblock %} \ No newline at end of file diff --git a/views.py b/views.py new file mode 100644 index 0000000..2b8c675 --- /dev/null +++ b/views.py @@ -0,0 +1,85 @@ +from flask import Blueprint, render_template,url_for, redirect, jsonify, request,Flask +import requests +# import requests +views = Blueprint(__name__, "views") + +app = Flask(__name__) + + +@views.route("/") +def home(): + # return "hello testing" + return render_template("index.html") + + +# add /views/profile/username +# http://127.0.0.1:8000/views/profile/username +# @views.route("/profile/") +# def profile(username): +# # return "hello testing" +# return render_template("index.html", name=username) + +# take query +# /views/profile?name=username +# http://127.0.0.1:8000/views/profile?name=username + +@views.route("/profile") +def profile(): + # return "hello testing" + # args=request.args + # name=args.get('name') + return render_template("track.html") + +# return json to return json need dictionary +@views.route("/json") +def get_json(): + return jsonify({'name': 'username', 'ID':123}) + +# redirect json +@views.route("/gotohome") +def gotohome(): + return redirect(url_for("views.home")) + +# --------------- +# stackify website +# IPStack key +# https://stackify.com/python-geocoder-a-guide-to-managing-locations-in-your-apps/ +#---------------- + +# +import json +# json.loads(symbols) + +key = "e88e972426c5be7ed2b8a1a45b4460dd" + + +@views.route('/track', methods=['POST',"GET"]) +def my_form_post(): + + if request.method == "POST": + ip = request.form['text'] + # processed_text = text.upper() + url = "http://api.ipstack.com/" + ip + "?access_key=" + key + r = requests.get(url) + print("r value", r.content) + longitude = r.json()["longitude"] + latitude = r.json()["latitude"] + contentt=r.json() + + + return render_template("trackpage.html",longitude =longitude ,latitude = latitude, contentt=contentt) + + + return render_template("form.html") + +# login +# Route for handling the login page logic +@views.route('/login', methods=['GET', 'POST']) +def login(): + error = None + if request.method == 'POST': + if request.form['username'] != 'admin' or request.form['password'] != 'admin': + error = 'Invalid Credentials. Please try again.' + else: + return redirect(url_for('home')) + return render_template('login.html', error=error) \ No newline at end of file