Commit
·
a0c14f1
1
Parent(s):
68934c7
Upload 5 files
Browse files- Dockerfile +31 -0
- main.py +47 -0
- requirements.txt +4 -0
- video_dict.pkl +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Use the official lightweight Python image.
|
| 3 |
+
# https://hub.docker.com/_/python
|
| 4 |
+
FROM python:3.11-slim
|
| 5 |
+
|
| 6 |
+
# Allow statements and log messages to immediately appear in the logs
|
| 7 |
+
ENV PYTHONUNBUFFERED True
|
| 8 |
+
|
| 9 |
+
# Copy local code to the container image.
|
| 10 |
+
ENV APP_HOME /app
|
| 11 |
+
WORKDIR $APP_HOME
|
| 12 |
+
COPY . ./
|
| 13 |
+
|
| 14 |
+
# Install production dependencies.
|
| 15 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
+
|
| 17 |
+
RUN useradd -m -u 1000 user
|
| 18 |
+
USER user
|
| 19 |
+
ENV HOME=/home/user \
|
| 20 |
+
PATH=/home/user/.local/bin:$PATH
|
| 21 |
+
|
| 22 |
+
WORKDIR $APP_HOME
|
| 23 |
+
|
| 24 |
+
COPY --chown=user . $HOME/app
|
| 25 |
+
|
| 26 |
+
# Run the web service on container startup. Here we use the gunicorn
|
| 27 |
+
# webserver, with one worker process and 8 threads.
|
| 28 |
+
# For environments with multiple CPU cores, increase the number of workers
|
| 29 |
+
# to be equal to the cores available.
|
| 30 |
+
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
|
| 31 |
+
CMD exec gunicorn --bind 0.0.0.0:7860 --workers 1 --threads 8 --timeout 0 main:app
|
main.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, Response, render_template, send_file
|
| 2 |
+
import requests
|
| 3 |
+
import random
|
| 4 |
+
import pickle as pkl
|
| 5 |
+
import pycountry
|
| 6 |
+
import datetime as dt
|
| 7 |
+
import pytz
|
| 8 |
+
|
| 9 |
+
with open('video_dict.pkl', 'rb') as f:
|
| 10 |
+
feed_dict = pkl.load(f)
|
| 11 |
+
|
| 12 |
+
app = Flask(__name__)
|
| 13 |
+
|
| 14 |
+
def get_ip_info(ip_address):
|
| 15 |
+
try:
|
| 16 |
+
response = requests.get(f"http://ipinfo.io/{ip_address}/json")
|
| 17 |
+
data = response.json()
|
| 18 |
+
return data
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return {"error": str(e)}
|
| 21 |
+
|
| 22 |
+
def latlon_to_pixel(loc):
|
| 23 |
+
latitude = float(loc.split(',')[0])
|
| 24 |
+
longitude = float(loc.split(',')[1])
|
| 25 |
+
|
| 26 |
+
y = ((90-latitude)/180)
|
| 27 |
+
x = ((longitude+180)/360)
|
| 28 |
+
return x*100, y*100
|
| 29 |
+
|
| 30 |
+
@app.route('/')
|
| 31 |
+
def index():
|
| 32 |
+
feed = random.randint(0, len(feed_dict) - 1)
|
| 33 |
+
url = feed_dict[feed]['url']
|
| 34 |
+
ip = ''.join(url.split('//')[-1]).split(':')[0]
|
| 35 |
+
info = get_ip_info(ip)
|
| 36 |
+
name = (info['city'] + ", " + info['region'] + ", " + pycountry.countries.get(alpha_2=info['country']).name).lower()
|
| 37 |
+
org = info['org'].lower()
|
| 38 |
+
timezone = pytz.timezone(info['timezone'])
|
| 39 |
+
time = dt.datetime.now(timezone)
|
| 40 |
+
loc = info['loc']
|
| 41 |
+
print(info)
|
| 42 |
+
X, Y = latlon_to_pixel(info['loc'])
|
| 43 |
+
print(url)
|
| 44 |
+
return render_template('index.html', name=name, url=url, info=info, time=time, ip=ip, org=org, loc=loc, X=X, Y=Y)
|
| 45 |
+
|
| 46 |
+
if __name__ == '__main__':
|
| 47 |
+
app.run(host='0.0.0.0', port='7860', debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask==2.2.5
|
| 2 |
+
pycountry==22.3.5
|
| 3 |
+
pytz==2023.3
|
| 4 |
+
requests==2.31.0
|
video_dict.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f4ec8ec38d1aec5adec11fce5a185d87b53eba7302080761c100998498474a65
|
| 3 |
+
size 291669
|