Feb-25-2022, 02:42 PM
Well, I now have a working fishmap in python3 with video uploads and all using this code:
thank you again Snippsat!!!
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() import cgi from flask import Flask, render_template, request from werkzeug.utils import secure_filename import os app = Flask(__name__) @app.route("/uploader", methods=["GET", "POST"]) def upload_file(): if request.method == "POST": f = request.files["file"] locnum = request.form.get('f') # f.save(secure_filename("temp" + str(locnum) + ".mp4")) f.save(os.path.join('/var/www/fishvid/', secure_filename('temp'+str(locnum)+'.mp4'))) return "file uploaded successfully" if __name__ == "__main__": app.run(host='0.0.0.0')and this is the main program fishmap.py
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() import cgi from datetime import date, datetime, timedelta import csv import os #html in python print ('''Content-Type: text/html\n''') print (''' <html><head> <title>J^2</title> <meta name="description" content="fish fishing map with Doppler Radar Map" /> <meta http-equiv="content-type" content="text/html" /> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <style> body {background: #1339de;} div#container { background: black; width: 50%; margin: 100px auto; color: white; border-radius: 1em; width: 1400px; height: 1125px; overflow:hidden; /* if you don't want a scrollbar, set to hidden */ overflow-x:hidden; /* hides horizontal scrollbar on newer browsers */ /* resize and min-height are optional, allows user to resize viewable area */ -webkit-resize:vertical; -moz-resize:vertical; resize:vertical; // min-height:1600px; } div#containerlil { background: black; width: 50%; margin: 100px auto; color: white; border-radius: 1em; width: 320px; height: 240px; overflow:hidden; /* if you don't want a scrollbar, set to hidden */ overflow-x:hidden; /* hides horizontal scrollbar on newer browsers */ /* resize and min-height are optional, allows user to resize viewable area */ -webkit-resize:vertical; -moz-resize:vertical; resize:vertical; // min-height:640px; } iframe#embedlil { width:320px; /* set this to approximate width of entire page you're embedding */ height:240px; /* determines where the bottom of the page cuts off */ margin-left:0px; /* clipping left side of page */ margin-top:0px; /* clipping top of page */ overflow:hidden; /* resize seems to inherit in at least Firefox */ -webkit-resize:none; -moz-resize:none; resize:none; } </style> <body><div id="main"><div id="site_content"><div id="content"> <h1>Doppler Map with Fishing Report!!!</h1> </div></div></div></body> <script type="text/javascript" > function go() { var m3=document.getElementsByName("c"); var m4=document.getElementsByName("d"); window.location.href = "https://lftr.biz/cgi-bin/fishmap.py" + m3(0).value+"+"+ m4(0).value; } </script> <script type="text/javascript" > function go2() { var m3=document.getElementsByName("e"); var m4=document.getElementsByName("f"); window.location.href = "https://lftr.biz/cgi-bin/fishmap.py" + m3(0).value+"+"+ m4(0).value; } </script> </html>''') print (''' <h4>Alert to a new fishing location...!!!!</h4> <form action="https://lftr.biz/cgi-bin/fishmap.py" onsubmit="go();"> Latitude (xxx.xxxx/-xxx.xxxx): <input type="text" name="c" value= "33.3866412"><br> Longitude (xxx.xxxx/-xxx.xxxx): <input type="text" name="d" value= "-118.4734779"><br> <input type="submit" value="Submit"> </form> ''') #lat,lng,report tuple as list (commented out bc i am using a local csv file so as to WRITE reports to current locations) #latlng = [(33.5987, -117.8826, ), (36.4147885,-118.9277509, ), (36.0765497,-118.9106086, ), (37.0396,-119.6483, ), (33.5901046, -117.870014, ), (33.5985056, -117.9033164, ), (33.6074678, -117.9309998, ), (33.6531, -118.0061, ), (33.7419998, -118.1875496, ), (34.4986553, -118.6108158, ), (34.2906126, -117.3599411, ), (34.565518, -114.3949421, ), (34.5133492, -114.3702769, ), (34.4548, -114.3755, ), (34.4495, -114.3724, ), (34.4494, -114.3712, )] # open and read lat,lng,report tuple as list in local .csv file = open("/var/www/cgi-bin/fishloclist.csv", "r") csv_reader = csv.reader(file) #make csv content a python3 list loc = [] for row in csv_reader: loc.append(row) #Reload information for subbmitting reports #pulls the variable values from the improved url #saves the report to the list #try or else just load with out updating via url when the url is standard form = cgi.FieldStorage() try: lat = float(form.getvalue("c")) lng = float(form.getvalue("d")) coord = (lat,lng,'') loc.append(coord) with open('/var/www/cgi-bin/fishloclist.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerows(loc) print ('location submited'+str(loc[-1])) except: print ('') try: report = str(form.getvalue("e")) locnum = int(form.getvalue("f")) loc[locnum].append(report) with open('/var/www/cgi-bin/fishloclist.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerows(loc) print ('report submited'+str(loc[locnum])) except: print ('') try: file = form.getvalue('videofile') # decodedfile = base64.b64decode(decodedfile) locnum = int(form.getvalue("f")) os.remove('fishvid/output'+str(locnum)+'.mp4') with open('fishvid/output'+str(locnum)+'.mp4', 'wb') as bfile: bfile.write(file) bfile.close() print ('The video was successfully saved') except: print ('') ###the next print section hosts ARCGIS API for JAVASCRIPT (in python) ##this happens with some integration to python variabes #also the loop will read how many locations by length of list then pull the tuple parts and use them seperately for each point with popups is iterated on one graphics layer #time variables import datetime from datetime import date, datetime, timedelta import datetime as dt import time day3 = dt.date.today()-dt.timedelta(days=3) tend = time.strftime('%Y'+'%m'+'%d') tminus = str(time.strftime('%Y'+'%m'))+str(int(time.strftime('%d'))-1) print ('''<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>ArcGIS API for JavaScript 4.22</title> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } </style> <link rel="stylesheet" href="https://js.arcgis.com/4.22/esri/themes/light/main.css" /> <script src="https://js.arcgis.com/4.22/"></script> <script>require(["esri/Map", "esri/views/SceneView", "esri/layers/SceneLayer","esri/layers/WMSLayer","esri/widgets/BasemapToggle","esri/layers/TileLayer","esri/layers/VectorTileLayer","esri/layers/GraphicsLayer","esri/layers/CSVLayer","esri/widgets/Search","esri/widgets/Locate","esri/widgets/Track","esri/Graphic","esri/layers/FeatureLayer", "esri/widgets/Editor", "esri/popup/content/AttachmentsContent","esri/popup/content/TextContent"], (Map, SceneView, SceneLayer,WMSLayer,BasemapToggle,TileLayer,VectorTileLayer,GraphicsLayer,CSVLayer,Search,Locate,Track,Graphic, FeatureLayer, Editor, AttachmentsContent, TextContent) => { const layer = new WMSLayer({url: "https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", sublayers: [{name: "nexrad-n0r-900913"}], refreshInterval:.25}); let map = new Map({ basemap: {baseLayers:[layer, new TileLayer({url: 'https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/?SRC_DATE= '''+str(tminus)+''' &SRC_DATE2= '''+str(tend)+''' '}), ]}, ground: "world-elevation",}); let view = new SceneView({container: "viewDiv", map: map, camera: {position: {x: '''+str(-118)+' , y:'+str(34)+''' , z: 12500000}, tilt: 0},}); const locate = new Locate({ view: view, useHeadingEnabled: false, goToOverride: function(view, options) { options.target.scale = 1500; return view.goTo(options.target); } }); view.ui.add(locate, "top-left"); const track = new Track({ view: view,graphic: new Graphic({symbol: {type: "simple-marker",size: "12px",color: "green",outline: {color: "#efefef", width: "1.5px"}}}),seHeadingEnabled: true}); view.ui.add(track, "top-left"); const search = new Search({view: view}); view.ui.add(search, "top-right"); const toggle = new BasemapToggle({view: view, nextBasemap: "hybrid"}); view.ui.add(toggle, "top-right"); const graphicsLayer = new GraphicsLayer(); map.add(graphicsLayer );''') length = len(loc) for x in range(length): report = str(loc[x][-1]) latitude = str(loc[x][0]) longitude = str(loc[x][1]) ####very long print statement below that makes the points w popups and takes reports print (''' var template'''+str(x)+''' = {title: 'Location:''' +str(x)+''' - Coordinates: ''' +latitude+' , '+longitude+' Report: '+report+ ''' ', content: function(){ var report = document.createElement("div"); report.className = "myClass"; report.innerHTML = "<h2>Location Video</h2><div id='containerlil'><video width='320' height='240' controls autoplay src='/fishvid/temp'''+str(x)+'''.mp4' type='video/mp4'></video></div><h2>SmashUpVideo</h2><div id='containerlil'><video width='320' height='240' controls autoplay src='/fishvid/fastfish.mp4' type='video/mp4'></video></div> <h1>Submit A New Fishing Report</h1><form action='https://lftr.biz/cgi-bin/fishmap.py' onsubmit='go2();'>Enter Report: <input type='text' name='e' value= 'date, observation, tips & tricks'><br><input name ='f' value= '''+str(x)+''' type='hidden'><input type='submit' value='Submit'> </form><form enctype = 'multipart/form-data' action = 'http://lftr.biz:5000/uploader' method = 'post'><p>Upload File For The Location, ie whats up on vid....: <input type = 'file' name = 'file' /><input name ='f' value= '''+str(x)+''' type='hidden'></p><p><input type = 'submit' value = 'Upload' /></p> "; return report; } }; const point'''+str(x)+''' = {type: "point", x: ''' +longitude+ ''' , y: ''' +latitude+ ''' , z: 4010}; const markerSymbol'''+str(x)+''' = {type: "simple-marker", color: [226, 119, 40], outline: {color: [255, 255, 255], width: 4}}; const pointGraphic'''+str(x)+''' = new Graphic({geometry: point'''+str(x)+''' , popupTemplate: template'''+str(x)+''' , symbol: markerSymbol'''+str(x)+'''}); graphicsLayer.add(pointGraphic'''+str(x)+''' ); ''') print (''' }); </script></head><body><div id="container"><div id="viewDiv"></div></div></body></html>''') #############################################################################[attachment=1627][attachment=1628][attachment=1629]
thank you again Snippsat!!!