Skip to content

Commit

Permalink
bulk delete/edit, total km calcultion and more
Browse files Browse the repository at this point in the history
  • Loading branch information
elblogbruno committed Aug 9, 2021
1 parent 41e0e16 commit 705db9f
Show file tree
Hide file tree
Showing 50 changed files with 2,012 additions and 335 deletions.
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from controller.models.models import Wanderpi
from controller import socketio
from controller.utils.watcher import ImagesWatcher
import threading
from flask_dropzone import Dropzone

app = create_app('dev')
dropzone = Dropzone(app)

if __name__ == '__main__':
#app.run(threaded=True, host="0.0.0.0")
Expand Down
7 changes: 7 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class Config:
SECRET_KEY = "fM3PEZwSRcbLkk2Ew82yZFffdAYsNgOddWoANdQo/U3VLZ/qNsOKLsQPYXDPon2t"

MAX_CONTENT_LENGTH = 200 * 1024 * 1024

DROPZONE_MAX_FILE_SIZE= 1024 # set max size limit to a large number, here is 1024 MB
DROPZONE_TIMEOUT=5 * 60 * 1000 # set upload timeout to a large number, here is 5 minutes
DROPZONE_MAX_FILES=30
DROPZONE_PARALLEL_UPLOADS=3 # set parallel amount
DROPZONE_UPLOAD_MULTIPLE=True # enable upload multiple

# session过期时间
PERMANENT_SESSION_LIFETIME = timedelta(days=7)

Expand Down
2 changes: 1 addition & 1 deletion controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setup_log(log_level):
# 为全局的日志工具对象(flask app使用的)添加日志记录器
logging.getLogger().addHandler(file_log_handler)

socketio = SocketIO()
socketio = SocketIO(async_mode='threading')

# 工厂函数: 由外界提供物料, 在函数内部封装对象的创建过程
def create_app(config_type): # 封装web应用的创建过程
Expand Down
8 changes: 6 additions & 2 deletions controller/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ def delete_all_wanderpis(self):
db.session.commit()
return True

def get_all_wanderpis(self):
return db.session.query(Wanderpi).filter(Wanderpi.travel_id == self.id).all()
def get_all_wanderpis(self, filter=None):
if filter:
is_image = (filter == 'image')
return db.session.query(Wanderpi).filter(Wanderpi.travel_id == self.id, Wanderpi.is_image == is_image).all()
else:
return db.session.query(Wanderpi).filter(Wanderpi.travel_id == self.id).all()

def delete(self, id):
if os.path.isdir(self.travel_folder_path):
Expand Down
45 changes: 38 additions & 7 deletions controller/modules/files/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import exifread
from datetime import datetime

import dateutil.parser as dparser

STATIC_FOLDER = '/static/wanderpis/'
VIDEO_EXTENSIONS = set(['mp4'])
Expand All @@ -18,34 +18,65 @@ def get_file_extension(filename):
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


#convert degree minute second to degree decimal
def dms_to_dd(dms):
dd = float(dms[0]) + float(dms[1])/60 + float(dms[2])/3600
return float(dd)

def get_lat_long_tags(path_name):
def get_image_tags(path_name, filename):
f = open(path_name, 'rb')

tags = exifread.process_file(f, stop_tag='GPS')
std_fmt = '%Y:%m:%d %H:%M:%S'

lat = 0
long = 0
creation_datetime = 0

for tag in tags.keys():
if tag == 'GPS GPSLatitude':
lat = dms_to_dd(tags[tag].values)
elif tag == 'GPS GPSLongitude':
long = dms_to_dd(tags[tag].values)
elif tag == 'EXIF DateTimeOriginal':
creation_datetime = datetime.strptime(tags['EXIF DateTimeOriginal'].values, std_fmt)

if creation_datetime == 0:
creation_datetime = dparser.parse(filename,fuzzy=True)

return lat, long, creation_datetime

def get_video_tags(path_name, filename):
f = open(path_name, 'rb')

tags = exifread.process_file(f, stop_tag='GPS')
std_fmt = '%Y:%m:%d %H:%M:%S.%f'

lat = 0
long = 0
creation_datetime = 0

for tag in tags.keys():
if tag == 'GPS GPSLatitude':
lat = dms_to_dd(tags[tag].values)
elif tag == 'GPS GPSLongitude':
long = dms_to_dd(tags[tag].values)
elif tag == 'EXIF DateTimeOriginal':
creation_datetime = datetime.strptime(tags['EXIF DateTimeOriginal'].values, std_fmt)

if lat == 0 and long == 0:
lat = 0
long = 0
if creation_datetime == 0:
try:
creation_datetime = dparser.parse(filename,fuzzy=True)
except:
creation_datetime = datetime.today()

return lat, long
return lat, long, creation_datetime

def create_folder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print('Error: Creating directory. ' + directory)
print('Error: Creating directory. ' + directory)

Loading

0 comments on commit 705db9f

Please sign in to comment.