Created
July 1, 2020 09:21
-
-
Save jasalt/d2649816ccc760b899086f6c9979e38a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # record frames from a public camera in jyväskylä city centre for timelapse purposes etc | |
| # uses threads, probably to not miss any frames, non threaded version commented in bottom | |
| # written in 2016 during random student event happening in the city centre | |
| # demo video https://youtu.be/tMSrBDwmtUo compiled with ffmpeg. | |
| # stutters a bit cause duplicate frames are not processed | |
| import requests | |
| from io import open as iopen | |
| from urlparse import urlsplit | |
| def requests_image(file_url, timestr): | |
| suffix_list = ['jpg', 'gif', 'png', 'tif', 'svg',] | |
| file_name = timestr + ".jpg" | |
| file_suffix = file_name.split('.')[1] | |
| i = requests.get(file_url + timestr) | |
| if file_suffix in suffix_list and i.status_code == requests.codes.ok: | |
| with iopen("./img/" + file_name, 'wb') as file: | |
| file.write(i.content) | |
| else: | |
| print("WTDF!!!!!!!!!!!!!") | |
| return False | |
| import time | |
| import thread | |
| def get_image(): | |
| timestr = str(int(time.time())) | |
| image_url = "http://217.152.196.254/jpg/1/image.jpg?" | |
| print("Getting " + timestr) | |
| requests_image(image_url, timestr) | |
| while True: | |
| thread.start_new_thread(get_image, ()) | |
| print("Get!") | |
| time.sleep(2) | |
| #### this is the non threaded version | |
| # def requests_image(file_url, timestr): | |
| # suffix_list = ['jpg', 'gif', 'png', 'tif', 'svg',] | |
| # file_name = timestr + ".jpg" | |
| # file_suffix = file_name.split('.')[1] | |
| # i = requests.get(file_url + timestr) | |
| # if file_suffix in suffix_list and i.status_code == requests.codes.ok: | |
| # with iopen("./history/" + file_name, 'wb') as file: | |
| # file.write(i.content) | |
| # else: | |
| # return False | |
| # import time | |
| # timeval = 1475169814 | |
| # while True: | |
| # timeval = timeval - 2 | |
| # timestr = str(timeval) | |
| # image_url = "http://217.152.196.254/jpg/1/image.jpg?" | |
| # print("Getting " + timestr) | |
| # requests_image(image_url, timestr) | |
| # # time.sleep(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment