Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
BIN
+3.24 KB
__pycache__/views.cpython-311.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
number="+449876066443" | ||
from flask import Flask | ||
from views import views | ||
|
||
app =Flask(__name__) | ||
app.register_blueprint(views) | ||
|
||
# | ||
if __name__ == "__main__": | ||
app.run(debug=True, port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# from flask import Flask, render_template, request | ||
# from flask_sqlalchemy import SQLAlchemy | ||
|
||
# app = Flask(__name__) | ||
# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///delivery.db' | ||
# db = SQLAlchemy(app) | ||
|
||
# class Delivery(db.Model): | ||
# id = db.Column(db.Integer, primary_key=True) | ||
# name = db.Column(db.String(50), nullable=False) | ||
# address = db.Column(db.String(100), nullable=False) | ||
# tracking_number = db.Column(db.String(50), nullable=False) | ||
# status = db.Column(db.String(50), nullable=False) | ||
|
||
# @app.route('/', methods=['GET', 'POST']) | ||
# def index(): | ||
# if request.method == 'POST': | ||
# name = request.form['name'] | ||
# address = request.form['address'] | ||
# tracking_number = request.form['tracking_number'] | ||
# delivery = Delivery(name=name, address=address, tracking_number=tracking_number, status='Shipped') | ||
# db.session.add(delivery) | ||
# db.session.commit() | ||
# return 'Delivery information stored.' | ||
# else: | ||
# return render_template('index.html') | ||
|
||
# @app.route('/delivery/<tracking_number>') | ||
# 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.' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("i am running"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<form action="/track"method="POST"> | ||
<input name="text"><h4>enter IP</h4> | ||
<input type="submit"> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/style.css') }}"> | ||
<title>FlaskBlog</title> | ||
|
||
<!-- <title></title> --> | ||
</head> | ||
<body> | ||
{% block content %} | ||
<h1>hello </h1> | ||
|
||
<h1>Welcome to TRacking website</h1> | ||
<h2>{{name}}</h2> | ||
<h3><a href="/track">Track IP</a></h3> | ||
{% endblock %} | ||
<script type="text/javascript" src="{{url_for('static', filename='index.js')}}"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<html> | ||
<head> | ||
<title>Flask Intro - login page</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="static/bootstrap.min.css" rel="stylesheet" media="screen"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Please login</h1> | ||
<br> | ||
<form action="" method="post"> | ||
<input type="text" placeholder="Username" name="username" value="{{ | ||
request.form.username }}"> | ||
<input type="password" placeholder="Password" name="password" value="{{ | ||
request.form.password }}"> | ||
<input class="btn btn-default" type="submit" value="Login"> | ||
</form> | ||
{% if error %} | ||
<p class="error"><strong>Error:</strong> {{ error }} | ||
{% endif %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends "index.html" %} | ||
{% block content %} | ||
<p>Here are your coordiantes </p> | ||
<p>longitude : {{longitude}}</p> | ||
<p>latitude : {{latitude}}</p> | ||
<p>content : {{contentt}}</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/<username>") | ||
# 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) |