使用时间戳、json和python

使用时间戳、json和python,python,json,time,stamp,Python,Json,Time,Stamp,此脚本使用time.sleep(3600)使请购单每隔1小时进行一次谷歌搜索,并生成一个包含所有短语的txt文件 他辗转了一天半。 我希望使用时间戳正确地执行此操作。有人能帮我吗 import urllib import urllib2 import json import time while 1: url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyA3758yM14aTX7aI9_v5AvK

此脚本使用time.sleep(3600)使请购单每隔1小时进行一次谷歌搜索,并生成一个包含所有短语的txt文件 他辗转了一天半。 我希望使用时间戳正确地执行此操作。有人能帮我吗

import urllib
import urllib2
import json
import time

while 1:
    url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyA3758yM14aTX7aI9_v5AvKI2X1m56HszI" 

    code = {

    "request": {
    "passengers": {
      "adultCount": 1,
      "childCount": 1
     },
    "slice": [
      {
        "origin": "SSA",
        "destination": "GRU",
        "date": "2015-06-19",
        "permittedDepartureTime":
        {
          "kind": "qpxexpress#timeOfDayRange",
          "earliestTime": "22:00",
          "latestTime": "23:00"
        }
      },
      {
        "origin": "GRU",
        "destination": "SSA",
        "date": "2015-06-30",
        "permittedDepartureTime":
        {
          "kind": "qpxexpress#timeOfDayRange",
          "earliestTime": "05:00",
          "latestTime": "12:00"
        }
      }
    ],
    "solutions": 3
      }
    }

    #hoje = "%s" % (time.strftime("%Y_%m_%d")) 

    jsonreq = json.dumps(code, encoding = 'utf-8')
    req = urllib2.Request(url, jsonreq, {'Content-Type': 'application/json'})
    flight = urllib2.urlopen(req)
    response = flight.read()
    flight.close()
    #print(response)
    print("----------------")


    texto=(response)
    v_file= open("ssaGRU.json" ,"a")

    #hora = time.strftime("%H:%M:%S %Z")
    v_file.write(texto)
    #v_file.write("[%s] Hora do json.\r\n" % (hora)) 
    v_file.close()

    time.sleep(15)
这将在每行输入之前打印您的当前时间,并在末尾添加一个空行,这样您不同时间的数据不会停留在一行上

如果需要,您还可以将
%m.%d.%y
添加到
当前时间
。如果
texto
不是字符串,请确保添加
str(texto)

这将在每行输入之前打印您的当前时间,并在末尾添加一个空行,这样您不同时间的数据不会停留在一行上


如果需要,您还可以将
%m.%d.%y
添加到
当前时间
。如果
texto
不是字符串,请确保添加
str(texto)

我发现您有几次尝试获取时间戳(
hoje
hora
)。现在。。。有什么问题吗?我发现您有几次尝试获取时间戳(
hoje
hora
)。现在。。。有什么问题吗?我发现您有几次尝试获取时间戳(
hoje
hora
)。现在。。。有什么问题吗?
current_time = time.strftime("%H:%M", time.localtime())
v_file = open("ssaGRU.json", "a")
v_file.write(str(current_time) + ': ')
v_file.write(texto + '\n')
v_file.close()