Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F24894986
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/create_surname b/create_surname
index a42e3c2..69e2653 100755
--- a/create_surname
+++ b/create_surname
@@ -1,68 +1,61 @@
#!/usr/bin/env python
"""
This script creates a new surname on Wikidata based on input.
TODO: check no item exists, with P31:Q101352
"""
import argparse
import json
import pywikibot
import os
# usage: create_surname.py [-h] surname
parser = argparse.ArgumentParser(
description='Creates a surname item on Wikidata.'
)
parser.add_argument(
'surname', metavar='surname',
nargs=1, help='the surname to create'
)
args = parser.parse_args()
surname = args.surname[0]
-# Consistency check
-# if surname[0].islower():
-# sys.stderr.write(
-# "Can't create a surname with the first letter in lower case.\n"
-# )
-# sys.exit(5);
-
# Creates item on Wikidata
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
data = {}
result = repo.editEntity(
{}, {},
summary="Creating empty item for surname " + surname
)
title = result.get('entity').get('id')
item = pywikibot.ItemPage(repo, title=title)
item.get()
script_dir = os.path.dirname(os.path.realpath(__file__))
# Gets whitelist latin languages to avoid create the element in other scripts.
latin_languages_file = os.path.join(script_dir, 'l10n/latin-whitelist.json')
with open(latin_languages_file) as data_file:
latin_languages = json.load(data_file)
# Gets descriptions from l10n file, and fill labels for these languages.
l10n_file = os.path.join(script_dir, 'l10n', 'surname.json')
with open(l10n_file) as data_file:
descriptions = json.load(data_file)
labels_languages = set(descriptions.keys()).intersection(latin_languages)
labels = {lang: surname for lang in latin_languages}
item.editLabels(labels, summary='Adding surname labels')
item.editDescriptions(descriptions, summary='Adding surname descriptions')
claim = pywikibot.Claim(repo, 'P31')
target = pywikibot.ItemPage(repo, 'Q101352')
claim.setTarget(target)
item.addClaim(claim)
print(title)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Mar 18, 13:27 (14 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3540023
Default Alt Text
(2 KB)
Attached To
Mode
rDWD Dæghrefn Wikidata access layer
Attached
Detach File
Event Timeline
Log In to Comment