コード例 #1
0
ファイル: main.py プロジェクト: CrossRef/ctn-exporter
def poll_deposits(username, password):
  for (token, ctn, doi, status) in cursor.execute("select token, ctn, doi, status from ctns where status = ?", [SUBMITTED]):
    response = session.get("https://api.crossref.org/deposits/{}".format(token), auth=(username, password))
    
    if response.status_code == 401:
      print("Bad username and password")
      exit()

    new_status = response.json()['message']['status']

    print("Update {} in {} status {} -> {}".format(ctn, doi, status, new_status))  
    cursor.execute("update ctns set status = ? where token = ?", [status, token])
    connection.commit()
コード例 #2
0
ファイル: main.py プロジェクト: CrossRef/ctn-exporter
def send_deposits(username, password):
  to_deposit = cursor.execute("select ctn, doi, registry from ctns where status = ?", [NOT_DEPOSITED])

  for (ctn, doi, registry) in to_deposit:
    print("Deposit {} in {}".format(ctn, doi))
    templated = template.format(doi=escape(doi), registry=escape(registry), ctn=escape(ctn))

    response = session.post("https://api.crossref.org/deposits", data=templated, auth=(username, password), headers={"Content-Type": "application/vnd.crossref.partial+xml"})

    if response.status_code != 200:
      print("Error depositing: {}".format(response.status_code))
      print(response.text)
    else:
      token = response.json()['message']['batch-id']
      status = response.json()['message']['status']
      cursor.execute("update ctns set token = ?, status = ? where ctn = ? and doi = ?", [token, status, ctn, doi])
      connection.commit()
      print("Status of {} in {}: {}".format(ctn, doi, status))