コード例 #1
0
    def _get_payload(query, query_id, dates, opts):
        """
        Create the Payload
        :param query: Query string
        :param dates: from -> Date from
        :param dates: to -> Date to
        :param opts: response -> response of the output
        :param opts: limit -> limit of rows for response
        :param opts: offset -> number, set the start of response
        :param opts: destination -> Destination for the results
        :return: Return the formed payload
        """
        date_from = default_from(dates['from'])
        date_to = default_to(dates['to']) if dates['to'] is not None else None

        payload = {
            "from":
            int(date_from / 1000) if isinstance(date_from,
                                                (int, float)) else date_from,
            "to":
            int(date_to / 1000) if isinstance(date_to,
                                              (int, float)) else date_to,
            "mode": {
                "type": opts['response']
            }
        }

        if dates.get("timeZone"):
            payload['timeZone'] = dates.get("timeZone")

        if query:
            payload['query'] = query

        if query_id:
            payload['queryId'] = query_id

        if opts['limit']:
            payload['limit'] = opts['limit']

        if opts['offset']:
            payload['offset'] = opts['offset']

        if opts["destination"]:
            payload['destination'] = opts['destination']

        return json.dumps(payload)
コード例 #2
0
 def test_default_to(self):
     ts1 = str(default_to())[:11]
     ts2 = str((dt.utcnow() - self.epoch).total_seconds() * 1000)[:11]
     self.assertTrue(ts1 == ts2)
コード例 #3
0
 def test_default_to(self):
     ts1 = default_to()
     ts2 = int((dt.utcnow() - self.epoch).total_seconds() * 1000)
     self.assertTrue(ts1 == ts2)