Beispiel #1
0
def commit():
  request = common.url_request("http://whatthecommit.com")
  with common.urlopen(request) as s:
    content = s.read().decode('utf-8', 'replace')

  message = re.search(r'<p>(.+?)\n', content).group(1)
  return message
 def get_token(self, password, tfa=None):
     platform = 'linux'
     device_id = self.device_id
     device_name = 'terminal-' + os.uname()[1]
     client_version = ''
     platform_version = ''
     data = {
         'username': self._u,
         'password': password,
         'platform': platform,
         'device_id': device_id,
         'device_name': device_name,
         'client_version': client_version,
         'platform_version': platform_version,
     }
     if tfa:
         headers = {
             'X-SEAFILE-OTP': tfa,
         }
     else:
         headers = None
     token_json = urlopen("{}/api2/auth-token/".format(self.URL),
                          data=data,
                          headers=headers)
     logger.debug('token for {} retrieved'.format(self._u))
     return json.loads(token_json)['token']
Beispiel #3
0
    def __init__(self, uri="AllSets.json", data=None):
        if data != None:
            self.extend(data)
            return

        card_database = None
        if os.path.isfile(uri):
            if os.path.exists(uri):
                with codecs.open(uri, "r", "utf-8") as f:
                    card_database = f.read()
            else:
                print("Cannot find %s" % uri)
        
        if not card_database:
            card_database = urlopen(ALL_SETS_JSON).read()
            card_database = card_database.decode("utf8")
        
        card_database = loads(card_database, encoding = "utf8")

        for k,v in card_database.items():
            if "cards" in v:
                for i in v["cards"]:
                    #print(i)
                    if "multiverseid" not in i:
                        continue

                    i["printings"] = [ k ]
                    self.append( Card(i) )
            else:
                self.append( Card(v) )
Beispiel #4
0
def executeBackstage(url, data, header, msg):
    status, stdout = common.urlopen(url, header=header, data=data)
    result = {"status": False}
    result["response"] = stdout
    if status == 0:
        try:
            jsonResult = json.loads(stdout)
            statusCode = int(jsonResult["status"])
            if statusCode == 1:
                result["status"] = True
                result["msg"] = msg
            else:
                result["status"] = False
                result["msg"] = jsonResult["msg"]
        except Exception, e1:
            result["status"] = False
            result["msg"] = stdout
Beispiel #5
0
def executeBackstage(url,data,header,msg):
    status,stdout = common.urlopen(url,header=header,data=data)
    result = {"status":False}
    result["response"] = stdout
    if status == 0:
        try:
            jsonResult = json.loads(stdout)
            statusCode = int(jsonResult["status"])
            if statusCode == 1:
                result["status"] = True
                result["msg"] = msg
            else:
                result["status"] = False
                result["msg"] = jsonResult["msg"]
        except Exception,e1:
            result["status"] = False
            result["msg"] = stdout
#!/usr/bin/env python3
"""
Осуществить POST запрос с передачей своих заголовков
"""

import urllib.request
import common

common.urlopen(
    urllib.request.Request('https://httpbin.org/post',
                           headers={'x-whom': 'Its me!'},
                           method='POST'))
Beispiel #7
0
#!/usr/bin/env python3
"""
Осуществить POST со своим body (json)
"""

import urllib.request
import json
import common

common.urlopen(
    urllib.request.Request('https://httpbin.org/post',
                           data=json.dumps({
                               'name': 'bubujka',
                               'age': 32
                           }).encode('utf-8'),
                           headers={
                               'x-whom': 'Its me!',
                               'content-type': 'application/json'
                           },
                           method='POST'))
Beispiel #8
0
def wikipedia(args):
    request = common.url_request("http://h4xxel.org/failboat/wikipedia.php?nick=n&args=" + common.quote(args))
    with common.urlopen(request) as s:
        content = s.read().decode('utf-8', 'replace')

    return content
 def get_repo_download_info(self, url, token):  #FIXME: rename function
     headers = {'Authorization': 'Token %s' % token}
     repo_info = urlopen(url, headers=headers)
     return json.loads(repo_info)