Skip to content

Commit

Permalink
fix(ods): Should PUT resources before publishing the dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Dec 19, 2024
1 parent 5317cf6 commit d93e73e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sync_openalex_affiliations_github_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import os
import pandas as pd
import requests
import time

load_dotenv()

# Config
GIT_PER_PAGE = 100
GIT_REPOSITORY_NAME = "dataesr/openalex-affiliations"
ODS_DATASET = "https://data.enseignementsup-recherche.gouv.fr/api/automation/v1.0/datasets/da_lyihp9"
ODS_FILE_ID = "re_agmowf"
OUTPUT_FILE_NAME = "github_issues.csv"

try:
Expand Down Expand Up @@ -80,10 +80,14 @@ def ods_sync():
url = f"{ODS_DATASET}/resources/files/"
headers = { "Authorization": f"apikey {ODS_API_KEY}" }
files = { "file": open(OUTPUT_FILE_NAME, "rb")}
response1 = requests.post(url, files=files, headers=headers)
print(response1.status_code)
response2 = requests.post(f"{ODS_DATASET}/publish/", headers=headers)
print(response2.status_code)
response = requests.post(url, files=files, headers=headers)
json = {
"datasource": { "type": "uploaded_file", "file": { "uid": response.json().get('uid') } },
"title": OUTPUT_FILE_NAME,
"type": "csvfile",
}
requests.put(f"{ODS_DATASET}/resources/{ODS_FILE_ID}/", headers=headers, json=json)
requests.post(f"{ODS_DATASET}/publish/", headers=headers)

def main():
data = []
Expand Down

0 comments on commit d93e73e

Please sign in to comment.