Example #1
0
def drawing(request):
    global pos, RefreshQueue

    while not RefreshQueue:
        try:
            i, j, k = pos.get(False)
            print("\t绘图位置:{0}  {1}".format(i, j))
            print("\t颜色信息(RGB):", k)
            print("\t对应画笔信息:", brush[str(tuple(k))])
            while True:
                # popen
                try:
                    ret = os.popen(request.format(i, j, brush[str(
                        tuple(k))])).readlines()[0]
                except Exception as e:
                    continue

                print("\t网络请求返回值:", ret)
                ret = json.loads(ret)
                if ret['code'] == 0:
                    break
                elif ret['code'] == -400:
                    time.sleep(ret['data']['time'])
                elif ret['code'] == -101:
                    print("需要重置cURL,目标cURL为:")
                    print(request)
                    exit(0)
                else:
                    print("\t出错啦,进入下一次循环")

        except queue.Empty as e:
            print("\t队列为空,等待中")
            time.sleep(30)

    return
Example #2
0
def request_uid(shortname):
    if debug: print("uid requested")
    request = "users.get?uids={uids}"
    request = "https://api.vk.com/method/" + request.format(uids=shortname)
    data = urllib.request.urlopen(request, None, 10)
    data = json.loads(data.read().decode('utf-8'))
    data = data["response"][0]
    cache_usersget(shortname, data)
    return data["uid"]
Example #3
0
def request_uid(shortname):
    if debug: print("uid requested")
    request = "users.get?uids={uids}"
    request = "https://api.vk.com/method/" + request.format(uids = shortname)
    data = urllib.request.urlopen(request, None, 10)
    data = json.loads(data.read().decode('utf-8'))
    data = data["response"][0]
    cache_usersget(shortname, data)
    return data["uid"]
Example #4
0
 def cassandra_initialisation(self, strategy, replication_factor):
     request = "CREATE KEYSPACE IF NOT EXISTS {0}" \
               " WITH replication = {{'class': '{1}', 'replication_factor': '{2}' }}"
     request = request.format(self.cassandra_keyspace, strategy,
                              replication_factor)
     self.session.execute(request)
     self.session.set_keyspace(self.cassandra_keyspace)
     table = """CREATE TABLE IF NOT EXISTS
                         {0} (
                             url text PRIMARY KEY,
                             author text,
                             twitter_id text,
                             twitter_username text,
                             )
                             WITH comment='Table of {1}'""".format(
         self.document_type, self.document_type)
     self.session.execute(table)
Example #5
0
def request_friends(user, short_request):
    if debug: print("friends requested")
    request = "friends.get?uid={uid}"
    if not short_request: request += "&fields={fields}"
    request = "https://api.vk.com/method/" + request.format(
        uid=user, fields="uid,first_name,last_name")
    if debug: print(request)
    x = urllib.request.urlopen(request, None, 10)
    x = json.loads(x.read().decode('utf-8'))
    if "response" not in x:
        request_userinfo(user)
        db["users"][user]["friends"] = []
        return set()
    x = x["response"]
    if short_request:
        cache_friends(user, x)
        return x
    for t in x:
        cache_usersget(t["uid"], t)
    friends = set(t["uid"] for t in x)
    cache_friends(user, friends)
    return friends
Example #6
0
def request_friends(user, short_request):
    if debug: print("friends requested")
    request = "friends.get?uid={uid}"
    if not short_request: request += "&fields={fields}"
    request = "https://api.vk.com/method/" + request.format(
        uid = user, fields = "uid,first_name,last_name")
    if debug: print(request)
    x = urllib.request.urlopen(request, None, 10)
    x = json.loads(x.read().decode('utf-8'))
    if "response" not in x:
        request_userinfo(user)
        db["users"][user]["friends"] = []
        return set()
    x = x["response"]
    if short_request:
        cache_friends(user, x)
        return x
    for t in x:
        cache_usersget(t["uid"], t)
    friends = set(t["uid"] for t in x)
    cache_friends(user, friends)
    return friends