def dl_weather_image(self, forecast_time): """ Attempts to download the weather image for the requested forecast_time from the NAS. Parameters: forecast_time - datetime object Returns the downloaded image. urllib raises some exception upon failure (see util.download_image) """ dt = forecast_time path_to_image = "/%4d/%02d/%02d/wcam0_%4d%02d%02d_%02d%02d.jpg" % \ (dt.year, dt.month, dt.day, dt.year, dt.month, dt.day, dt.hour, dt.minute) image_url = "http://"+NAS_ADDR[0]+":"+str(NAS_ADDR[1])+path_to_image return util.download_image(image_url)
def prase_all_item(html, debug=False): temp_session = requests.Session() temp_session.headers = header pattern = re.compile('(\d{4}-\d{1,2}-\d{1,2})') soup = BeautifulSoup(html, 'lxml') li_list = soup.select('ul[class="ml waterfall cl"] li') for li in li_list: a = li.select('div[class="c cl"] a')[0] movie_url = urljoin('http://www.52av.tv', a['href']) image_url = a.select('img')[0]['src'] title = a['title'] span = li.select('div[class="auth cl"] span') try: issue_time = span[0]['title'] except: content = li.select('div[class="auth cl"]')[0] res = pattern.findall(content.text) if len(res) > 0: issue_time = res[0] else: issue_time = datetime.datetime.now().strftime('%Y-%m-%d') movie_object_id = get_md5(movie_url) if query_from_sql(movie_object_id): continue image_path = download_image(image_url, movie_object_id) if not image_path: image_path = 'None' try: video_url = get_m3u8_url(temp_session, movie_url) except: video_url = None if not video_url: continue if debug: print('[*]', video_url) issue_time = datetime.datetime.strptime(issue_time, '%Y-%m-%d') parmars = (title, movie_url, image_url, image_path, issue_time, movie_object_id, video_url) insert_to_mysql(parmars)
def download_image_with_thread(entry): if _FINISH: return url, path = entry result = download_image(url, path) return (url, result)
import os import util if __name__ == "__main__": # A simple stopwatch I made for measuring execution time. sw = util.stopwatch() LIB_FILENAME = "libcloudiness.so" LIBPATH = os.path.join(os.getcwd(), "lib", LIB_FILENAME) # Load the shared library. This library has been compiled with some # particular flags. Look at the Makefile accompanying it. libcloudiness = ctypes.cdll.LoadLibrary(LIBPATH) # Download the image image = util.download_image("http://i.imgur.com/MDsb5.jpg") image_size = len(image) # This is one of the functions declared in the library f = libcloudiness.calc_cloudiness f.restype = ctypes.c_double # I think all functions default to int as return type, therefore I set this # to match the actual return type of the C function (using ctypes.c_<type>) # cloudiness.restype = ctypes.c_double # create buffer to hold raw data, this is passed as argument to the C function raw_image = (ctypes.c_ubyte * image_size)() # copies the contents of image to raw_image ctypes.memmove(ctypes.byref(raw_image), image, image_size)