/
download.py
121 lines (100 loc) · 3.15 KB
/
download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# For system_test
## By sek su
############### CONFIG ##############
ftpAddr = '161.246.5.152'
ftpUser = 'root'
ftpPass = '123456'
ftpDir = 'ipcam'
# tokens = ['a121','a122','a123']
#####################################
import sys
import pylab
import cv2
#import imageio
from time import gmtime
from ftplib import FTP
from urllib import urlretrieve
from urllib import urlcleanup
import os
import time
from os.path import join, getsize
sys.path.append('/home/pansek/webserver')
import django
os.environ["DJANGO_SETTINGS_MODULE"] = 'webserver.settings'
django.setup()
from camera.models import Camera_Detail
tokens = []
for obj in Camera_Detail.objects.all():
tokens.append(obj.token)
minStore = ''
listFileName = []
previousVideo_name = ''
while 1:
ftp = FTP(ftpAddr)
ftp.login(ftpUser,ftpPass)
year = str(gmtime().tm_year)
if(gmtime().tm_mon < 10):
month = '0'+str(gmtime().tm_mon)
else:
month = str(gmtime().tm_mon)
if(gmtime().tm_mday < 10):
day = '0'+str(gmtime().tm_mday)
else:
day = str(gmtime().tm_mday)
if(((gmtime().tm_hour+7)%24) < 10):
hour = '0'+str((gmtime().tm_hour+7)%24)
else:
hour = str((gmtime().tm_hour+7)%24)
if(((gmtime().tm_min-3)%60) < 10):
minute = '0'+str((gmtime().tm_min-1)%60)
else:
minute = str((gmtime().tm_min-3)%60)
if((gmtime().tm_sec) < 10):
sec = '0'+str(gmtime().tm_sec)
else:
sec = str(gmtime().tm_sec)
minStore = minute
ftp.cwd("/ipcam/"+year+""+month+""+day+"/"+hour+"00/")
currentPath = ftp.nlst()
#print("/ipcam/"+year+""+month+""+day+"/"+hour+"00/")
for filename_video in currentPath:
#print(filename_video)
#print(token+year+month+day+hour+minStore)
for token in tokens:
if(filename_video.startswith(token+year+month+day+hour+minStore) and filename_video.endswith(".avi")):
non = True
for name in listFileName:
if(filename_video == name):
non = False
if(non == True):
listFileName.append(filename_video)
# if(previousVideo_name):
# file = open("video/"+previousVideo_name, 'rb')
# print("previous size : "+file)
print(filename_video)
urlcleanup()
urlretrieve("ftp://"+ftpUser+":"+ftpPass+"@"+ftpAddr+"/ipcam/"+year+""+month+""+day+"/"+hour+"00/"+str(filename_video),"video/"+str(filename_video))
previousVideo = "/ipcam/"+year+""+month+""+day+"/"+hour+"00/"+str(filename_video)
previousVideo_name = str(filename_video)
f = open('downloadList','a+')
f.write(filename_video+'\n')
f.close
time.sleep(1)
print("Download complete")
if(minStore != minute):
minStore = minute
listFileName = []
time.sleep(1)
#urlretrieve("ftp://"+ftpUser+":"+ftpPass+"@"+ftpAddr+"/ipcam/"+year+""+mouth+""+day+"/"+hour+"00/"+token+""+year+""+mouth+""+hour+,"source/input.avi")
#filename = '/home/pansek/workspace/source/input.avi'
#vid = imageio.get_reader(filename, 'ffmpeg')
#image = vid.get_data(100)
#rgbImg = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# print(year)
# print(month)
# print(day)
# print(hour)
# print(minute)
# print(sec)
# cv2.waitKey(0)
# cv2.destroyAllWindows()