-parser = argparse.ArgumentParser(description='Creates a given name item on Wikidata.')
-parser.add_argument('givenname', metavar='givenname', nargs=1, help='the given name to create')
-parser.add_argument('genre', metavar='genre', nargs='?', default='D', help='M for a male, F for a female, U for an unisex given name', choices=['M','F','U','D'])
+# Usage: create_givenname.py [-h] givenname
+parser = argparse.ArgumentParser(
+ description='Creates a given name item on Wikidata.'
+)
+parser.add_argument(
+ 'givenname',
+ metavar='givenname', nargs=1,
+ help='the given name to create'
+)
+parser.add_argument(
+ 'genre',
+ metavar='genre', nargs='?', default='D',
+ help='M for a male, F for a female, U for an unisex given name',
+ choices=['M', 'F', 'U', 'D']
+)
args = parser.parse_args()
givenname = args.givenname[0]
genre = args.genre[0]
-#Consistency check
+# Consistency check
if givenname[0].islower():
- sys.stderr.write("Can't create a givenname with the first letter in lower case.\n")
- sys.exit(5);
+ sys.stderr.write(
+ "Can't create a givenname with the first letter in lower case.\n"
+ )
+ sys.exit(5)
-#Creates item on Wikidata
-import pywikibot
+# Creates item on Wikidata
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
data = {}
-result = repo.editEntity({}, {}, summary = "Creating empty item for given name " + givenname )
+result = repo.editEntity(
+ {}, {},
+ summary="Creating empty item for given name " + givenname
+)
title = result.get('entity').get('id')
item = pywikibot.ItemPage(repo, title=title)
item.get()
@@ -38,19 +54,19 @@
'fr': givenname,
'en': givenname
}
-item.editLabels(labels, summary = 'Adding given name labels')
+item.editLabels(labels, summary='Adding given name labels')
description = {
'en': 'given name',
'fr': 'prénom'
}
-item.editDescriptions(description, summary = 'Adding given name descriptions')
+item.editDescriptions(description, summary='Adding given name descriptions')
genre_items = {
- 'D': 'Q202444',
- 'M': 'Q12308941',
- 'F': 'Q11879590',
- 'U': 'Q3409032'
+ 'D': 'Q202444',
+ 'M': 'Q12308941',
+ 'F': 'Q11879590',
+ 'U': 'Q3409032'
}
claim = pywikibot.Claim(repo, 'P31')
diff --git a/create_surname b/create_surname
--- a/create_surname
+++ b/create_surname
@@ -7,26 +7,35 @@
"""
import argparse
-import sys
+import pywikibot
-#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')
+# 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")
+# Consistency check
+# if surname[0].islower():
+# sys.stderr.write(
+# "Can't create a surname with the first letter in lower case.\n"