Skip to content

Instantly share code, notes, and snippets.

@ansmirnov
Last active January 14, 2016 09:15
Show Gist options
  • Save ansmirnov/2a6946a8593b92869b12 to your computer and use it in GitHub Desktop.
Save ansmirnov/2a6946a8593b92869b12 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'Andrey Smirnov'
__email__ = 'mail@ansmirenov.ru'
import requests
import json
import sys
from requests.auth import HTTPBasicAuth
def check1(phone):
try:
res = requests.get('http://mnp.tele2.ru/gateway.php?%s' % phone).json()
return (int(res['response']['geocode']['code']), int(res['response']['mnc']['code']))
except:
return None
def check2(phone):
try:
res = requests.get('http://moscow.shop.megafon.ru/get_ajax_page.php?action=getMsisdnInfo&msisdn=7%s' % phone).json()
return (int(res['region_id']), int(res['operator_id']))
except:
return None
def write_log(logname, msg):
f = open(logname, 'a')
f.write(msg)
f.close()
def run(ph):
c1, c2 = check1(ph), check2(ph)
log = 'log/check_oper_id/err.log'
if c1 != c2:
write_log(log, 'Разный результат проверки')
return
if c1 is None:
write_log(log, 'Сайты недоступны')
return
print '%d=%d' % c1
run(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment