Skip to content

Instantly share code, notes, and snippets.

@xxnjdlys
Created May 4, 2017 13:35
Show Gist options
  • Save xxnjdlys/046aac8b904b1a3748dac570f367525c to your computer and use it in GitHub Desktop.
Save xxnjdlys/046aac8b904b1a3748dac570f367525c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 十三姐家的小钻风
# @Time : 04/05/2017 20:54
# @File : checkRouterJs.py
import hashlib
import requests
import json
from io import BytesIO
from zipfile import ZipFile
def getJsonValue(key):
response = requests.get('http://tv1.wukongtv.com/box/downsource?n=router')
response = json.loads(response.text)
md5 =response['data'][key]
return md5
def md5sum(file):
m = hashlib.md5()
str = file.read()
m.update(str)
return m.hexdigest()
def getUnzipFile(file_url):
url = requests.get(file_url)
zipfile = ZipFile(BytesIO(url.content))
zip_names = zipfile.namelist()
if len(zip_names) == 1:
file_name = zip_names.pop()
extracted_file = zipfile.open(file_name)
return extracted_file
onlineMd5 = getJsonValue('md5')
routerJSUrl = getJsonValue("url")
unzipFile = getUnzipFile(routerJSUrl)
localMd5 = md5sum(unzipFile)
print('md5-interface: ', onlineMd5)
print('md5-in-zip: ', localMd5)
if onlineMd5 != localMd5:
print("\nAll I want to say is #$*#%&@*#)!$&!@*#*&%)!@#*\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment