This repository was archived by the owner on Feb 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Fetch entities #7
Open
quorth0n
wants to merge
2
commits into
master
Choose a base branch
from
wh-polents
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Chron. | ||
Copyright (C) 2018 Alisa Belyaeva, Ata Ali Kilicli, Amaury Martiny, | ||
Daniil Mordasov, Liam O’Flynn, Mikhail Orlov. | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
""" | ||
|
||
from datetime import datetime | ||
import requests | ||
import os | ||
|
||
URL = "https://query.wikidata.org/sparql" | ||
QUERY = """ | ||
SELECT ?entity ?predecessors | ||
WHERE | ||
{ | ||
VALUES ?countryclass { wd:Q3024240 wd:Q6256 } | ||
?entity wdt:P31 ?countryclass ; | ||
wdt:P571 ?inception . | ||
OPTIONAL { ?entity wdt:P576 ?dissolved } . | ||
OPTIONAL { ?entity wdt:P155 ?predecessors } . | ||
FILTER (?inception < "1815-01-01T00:00:00Z"^^xsd:dateTime) | ||
FILTER (?dissolved >= "1789-01-01T00:00:00Z"^^xsd:dateTime || !Bound(?dissolved) ) | ||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } | ||
} | ||
""" | ||
R_ENTITIES = requests.get(URL, params={"format": "json", "query": QUERY}) | ||
ENTITIES = R_ENTITIES.json() | ||
|
||
for entity in ENTITIES["results"]["bindings"]: | ||
data = { | ||
"wikidata_id": int(entity["entity"]["value"].split("Q", 1)[1]), | ||
"color": "#fff", # TODO: change | ||
"admin_level": 1, | ||
"predecessors": [] # entity["predecessors"]["value"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FKEYs are enforced on a db level to maintain integrity, should we change this to be able to store predecessor relationships to entities not in our db? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afaik predecessor field was disabled for mvp and primary key has been changed to id |
||
} | ||
r_te = requests.post( | ||
os.getenv("API_ROOT", "http://localhost/api/") + "/territorial-entities/", | ||
data, | ||
params={"format": "json"}, | ||
) | ||
print(str(r_te.status_code) + ": " + r_te.reason) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are "wish" colors to be assigned manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it's an int field in database.