예제 #1
0
파일: widgets.py 프로젝트: ckazzku/taski
 def add_data(self):
     data = Data.get_data()
     data['id'] = None  # чтобы на сервере id сгенерилось
     Logger.debug('Add data: {}'.format(data))
     data = json.dumps(data)
     RestClient.post(data)
     RestClient.get()
예제 #2
0
        client = RestClient(user, password)
        i = 0
        j = args.batch

        # Cut the kws list in batches
        while j < len(kws) + args.batch:
            post_data = {}
            post_data[len(post_data)] = dict(
                language_code=args.language_code,
                location_code=args.location_code,
                keywords=kws[i:j],
                tag=tag,
            )

            response = client.post(
                "/v3/keywords_data/google/search_volume/task_post", post_data)
            if response["status_code"] == 20000:
                for task in response["tasks"]:
                    data = dict()
                    data["nb_requests"] = len(task["data"]["keywords"])
                    data["first_kw"] = task["data"]["keywords"][0]
                    data["last_kw"] = task["data"]["keywords"][-1]
                    data["status"] = task["status_message"]
                    data["id"] = task["id"]
                    data["tag"] = task["data"]["tag"]
                    with open(filename, 'a', newline='') as file:
                        writer = csv.DictWriter(file,
                                                fieldnames=fields,
                                                delimiter=args.sep)
                        writer.writerow(data)
                        file.close()
예제 #3
0
        # Cut the kws list in batches
        while j < len(kws) + args.batch:
            post_data = dict()
            for kw in kws[i:j]:
                post_data[len(post_data)] = dict(
                    language_code=args.language_code,
                    location_code=args.location_code,
                    keyword=kw,
                    priority=priority,
                    depth=args.nb_results,
                    device=args.device,
                    tag=tag,
                    calculate_rectangles=args.pixels,
                )

            response = client.post("/v3/serp/google/organic/task_post",
                                   post_data)
            if response["status_code"] == 20000:
                for task in response["tasks"]:
                    data = dict()
                    data["request"] = task["data"]["keyword"]
                    data["status"] = task["status_message"]
                    data["id"] = task["id"]
                    data["tag"] = task["data"]["tag"]
                    writer.writerow(data)
                print("Batch {} done.".format(int((i / args.batch) + 1)))
            else:
                print("Error. Code: %d Message: %s" %
                      (response["status_code"], response["status_message"]))

            i = j
            j += args.batch