import json
import requests
# Utility to pretty-print json.
def jprint(obj):
# create a formatted string of the Python JSON object
print(json.dumps(obj, sort_keys=True, indent=4))
resp = requests.get("https://archive.softwareheritage.org/api/1/stat/counters/")
counters = resp.json()
jprint(counters)
{
"content": 10150827430,
"directory": 8469778261,
"origin": 156417833,
"person": 42563041,
"release": 17292067,
"revision": 2128152083
}
resp = requests.get("https://archive.softwareheritage.org/api/1/origin/search/alambic/")
origins = resp.json()
print("We found",len(origins),"entries.")
for origin in origins[1:10]:
print('- ',origin['url'])
We found 52 entries.
- https://github.com/royal-alambic-club/sauron
- https://github.com/scamberlin/alambic
- https://github.com/WebTales/alambic-connector-mongodb
- https://github.com/WebTales/alambic
- https://github.com/AssoAlambic/alambic-website
- https://bitbucket.org/nayoub/alambic.git
- https://github.com/Alexandru-Dobre/alambic-connector-rest
- https://github.com/WebTales/alambic-connector-diffbot
- https://github.com/WebTales/alambic-connector-firebase
resp = requests.get("https://archive.softwareheritage.org/api/1/origin/https://github.com/borisbaldassari/alambic/get/")
found = resp.json()
jprint(found)
{
"origin_visits_url": "https://archive.softwareheritage.org/api/1/origin/https://github.com/borisbaldassari/alambic/visits/",
"url": "https://github.com/borisbaldassari/alambic"
}
resp = requests.get("https://archive.softwareheritage.org/api/1/origin/https://github.com/borisbaldassari/alambic/visits/")
found = resp.json()
length = len(found)
print("Number of visits found: {}.".format(length))
print("With dates:")
for visit in found:
print("-",visit['visit'],visit['date'])
print("\nExample of a single visit entry:")
jprint(found[0])
Number of visits found: 5.
With dates:
- 5 2021-01-01T19:35:41.308336+00:00
- 4 2020-02-06T10:41:45.700641+00:00
- 3 2019-09-01T22:38:12.056537+00:00
- 2 2019-06-16T04:52:18.162914+00:00
- 1 2019-01-30T07:19:20.799217+00:00
Example of a single visit entry:
{
"date": "2021-01-01T19:35:41.308336+00:00",
"metadata": {},
"origin": "https://github.com/borisbaldassari/alambic",
"origin_visit_url": "https://archive.softwareheritage.org/api/1/origin/https://github.com/borisbaldassari/alambic/visit/5/",
"snapshot": "6436d2c9b06cf9bd9efb0b4e463c3fe6b868eadc",
"snapshot_url": "https://archive.softwareheritage.org/api/1/snapshot/6436d2c9b06cf9bd9efb0b4e463c3fe6b868eadc/",
"status": "full",
"type": "git",
"visit": 5
}
# Store snapshot id
snapshot = found[0]['snapshot']
print("Snapshot is {}.".format(snapshot))
Snapshot is 6436d2c9b06cf9bd9efb0b4e463c3fe6b868eadc.
snapshotr = requests.get("https://archive.softwareheritage.org/api/1/snapshot/{}/".format(snapshot))
snapshotj = snapshotr.json()
jprint(snapshotj)
{
"branches": {
"HEAD": {
"target": "refs/heads/master",
"target_type": "alias",
"target_url": "https://archive.softwareheritage.org/api/1/revision/6dd0504b43b4459d52e9f13f71a91cc0fc445a19/"
},
"refs/heads/devel": {
"target": "e298b8c5692b18928013a68e41fd185419515075",
"target_type": "revision",
"target_url": "https://archive.softwareheritage.org/api/1/revision/e298b8c5692b18928013a68e41fd185419515075/"
},
"refs/heads/features/cr152_anonymise_data": {
"target": "ba3e0dcbfa0cb212a7186e9e62efb6dafe7fe162",
"target_type": "revision",
"target_url": "https://archive.softwareheritage.org/api/1/revision/ba3e0dcbfa0cb212a7186e9e62efb6dafe7fe162/"
},
"refs/heads/features/cr164_github_project": {
"target": "0005abb080e4c67a97533ee923e9d28142877752",
"target_type": "revision",
"target_url": "https://archive.softwareheritage.org/api/1/revision/0005abb080e4c67a97533ee923e9d28142877752/"
},
"refs/heads/features/cr165_github_its": {
"target": "0005abb080e4c67a97533ee923e9d28142877752",
"target_type": "revision",
"target_url": "https://archive.softwareheritage.org/api/1/revision/0005abb080e4c67a97533ee923e9d28142877752/"
},
"refs/heads/features/cr89_gitlabwizard": {
"target": "b941fd5f93a6cfc2349358b891e47d0fffe0ed2d",
"target_type": "revision",
"target_url": "https://archive.softwareheritage.org/api/1/revision/b941fd5f93a6cfc2349358b891e47d0fffe0ed2d/"
},
"refs/heads/master": {
"target": "6dd0504b43b4459d52e9f13f71a91cc0fc445a19",
"target_type": "revision",
"target_url": "https://archive.softwareheritage.org/api/1/revision/6dd0504b43b4459d52e9f13f71a91cc0fc445a19/"
}
},
"id": "6436d2c9b06cf9bd9efb0b4e463c3fe6b868eadc",
"next_branch": null
}
print('Revision ID is',snapshotj['id'])
master_url = snapshotj['branches']['refs/heads/master']['target_url']
masterr = requests.get(master_url)
masterj = masterr.json()
jprint(masterj)
Revision ID is 6436d2c9b06cf9bd9efb0b4e463c3fe6b868eadc
{
"author": {
"email": "boris.baldassari@gmail.com",
"fullname": "Boris Baldassari <boris.baldassari@gmail.com>",
"name": "Boris Baldassari"
},
"committer": {
"email": "boris.baldassari@gmail.com",
"fullname": "Boris Baldassari <boris.baldassari@gmail.com>",
"name": "Boris Baldassari"
},
"committer_date": "2020-11-01T12:55:13+01:00",
"date": "2020-11-01T12:55:13+01:00",
"directory": "fd9fe3477db3b9b7dea63509832b3fa99bdd7eb8",
"directory_url": "https://archive.softwareheritage.org/api/1/directory/fd9fe3477db3b9b7dea63509832b3fa99bdd7eb8/",
"extra_headers": [],
"history_url": "https://archive.softwareheritage.org/api/1/revision/6dd0504b43b4459d52e9f13f71a91cc0fc445a19/log/",
"id": "6dd0504b43b4459d52e9f13f71a91cc0fc445a19",
"merge": false,
"message": "#163 Fix dygraphs zero padding in forums plugin.\n",
"metadata": {},
"parents": [
{
"id": "a4a2d8925c1cc43612602ac28e4ca9a31728b151",
"url": "https://archive.softwareheritage.org/api/1/revision/a4a2d8925c1cc43612602ac28e4ca9a31728b151/"
}
],
"synthetic": false,
"type": "git",
"url": "https://archive.softwareheritage.org/api/1/revision/6dd0504b43b4459d52e9f13f71a91cc0fc445a19/"
}
root_url = masterj['directory_url']
rootr = requests.get(root_url)
rootj = rootr.json()
for f in rootj:
print('-',f['name'])
#jprint(rootj)
- .dockerignore
- .env
- .gitignore
- CODE_OF_CONDUCT.html
- CODE_OF_CONDUCT.md
- LICENCE.html
- LICENCE.md
- Readme.md
- doc
- docker
- docker-compose.run.yml
- docker-compose.test.yml
- dockercfg.encrypted
- mojo
- resources
mealr = requests.post("https://archive.softwareheritage.org/api/1/vault/directory/3ee1366c6dd0b7f4ba9536e9bcc300236ac8f200/")
mealj = mealr.json()
jprint(mealj)
{
"fetch_url": "https://archive.softwareheritage.org/api/1/vault/directory/3ee1366c6dd0b7f4ba9536e9bcc300236ac8f200/raw/",
"id": 379321799,
"obj_id": "3ee1366c6dd0b7f4ba9536e9bcc300236ac8f200",
"obj_type": "directory",
"progress_message": null,
"status": "done"
}
statusr = requests.get("https://archive.softwareheritage.org/api/1/vault/directory/3ee1366c6dd0b7f4ba9536e9bcc300236ac8f200/")
statusj = statusr.json()
jprint(statusj)
{
"fetch_url": "https://archive.softwareheritage.org/api/1/vault/directory/3ee1366c6dd0b7f4ba9536e9bcc300236ac8f200/raw/",
"id": 379321799,
"obj_id": "3ee1366c6dd0b7f4ba9536e9bcc300236ac8f200",
"obj_type": "directory",
"progress_message": null,
"status": "done"
}