Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Revised code for PYTHON Security webcam using WEB Page MD HARRINGTON
- import cv2
- import ftplib
- import sched, time
- import geocoder
- from requests import get
- from datetime import datetime
- # this is the function that will be called on starting thread
- def saveImage(s):
- print(s)
- ret,frame = vid.read()
- vid.release() #releasing camera immediately after capturing picture
- now = datetime.now() # current date and time
- date_time = now.strftime("%d/%m/%Y, %H:%M:%S") +"\n"
- ip = get('https://api.ipify.org').content.decode('utf8')
- str1 = ('{}'.format(ip))
- # concat strings
- text = str1 + '\n' + date_time
- y_start = 40
- y_increment = 50
- for i, line in enumerate(text.split('\n')):
- y = y_start + i*y_increment
- cv2.putText(frame ,
- line,
- org=(10, y),
- fontFace=cv2.FONT_HERSHEY_SCRIPT_COMPLEX, fontScale=1, color=(255,255,255),
- thickness=1)
- cv2.imwrite('img.jpg', frame)
- def uploadtoFTPServer():
- # Fill Required Information
- HOSTNAME = "x12.x10hosting.com"
- USERNAME = "YOUR LOGIN"
- PASSWORD = "YOUR FTP PASSWORD "
- filename = "img.jpg"
- ftp_server = ftplib.FTP(HOSTNAME, USERNAME, PASSWORD)
- # force UTF-8 encoding
- ftp_server.encoding = "utf-8"
- ftp_server.cwd("/domains/eliteprojects.x10host.com/public_html")
- with open(filename, "rb") as file:
- # data = []
- #ftp_server.dir(data.append)
- #for line in data:
- #print ( "-", line)
- # Command for Uploading the file "STOR filename"
- ftp_server.storbinary(f"STOR {filename}", file)
- time.sleep(2)
- ftp_server.quit()
- # main execution starts here
- while(True):
- vid = cv2.VideoCapture(0)
- vid.set(3, 640)
- vid.set(4, 480)
- time_now = time.time()
- saveImage(time_now)
- time.sleep(1)
- uploadtoFTPServer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement