import pywikibot
site = pywikibot.Site('id', 'wikipedia')
fileList = []
with open("fairuse.txt") as f:
    for line in f:
        if (len(line) > 1):
            fileList.append(line)
len(fileList)
30506
pageList = set()
for fileName in fileList:
    file = pywikibot.FilePage(site, fileName)
    pageList.update(page for page in site.imageusage(file))

print(len(pageList))
Sleeping for 5.0 seconds, 2017-07-13 14:19:27
print(len(pageList))
  File "<ipython-input-112-e6c2e600dcec>", line 2
    f.write("\n".join([blp[0].title() + "," + str(blp[1]) for blp in blpList]))print(len(pageList))
                                                                                   ^
SyntaxError: invalid syntax
with open("fairuse-usage.txt", "w") as f:
    f.write("\n".join([page.title() for page in pageList]))
print(help(site.pagecategories))
Help on method pagecategories in module pywikibot.site:

pagecategories(page, total=None, content=False, withSortKey=NotImplemented, step=NotImplemented) method of pywikibot.site.APISite instance
    Iterate categories to which page belongs.
    
    @param content: if True, load the current content of each iterated page
        (default False); note that this means the contents of the
        category description page, not the pages contained in the category

None
blpList = set()
for page in pageList:
    categories = site.pagecategories(page)
    for category in categories:
        if category.title(withNamespace=False).startswith("Orang hidup"):
            blpList.add((page, category))
Sleeping for 5.0 seconds, 2017-07-14 13:20:40
Sleeping for 5.0 seconds, 2017-07-14 13:20:45
Sleeping for 5.0 seconds, 2017-07-14 13:26:16
Sleeping for 5.0 seconds, 2017-07-14 13:26:21
Sleeping for 5.0 seconds, 2017-07-14 13:26:26
WARNING: Http response status 503
WARNING: Non-JSON response received from server wikipedia:id; the server may be down.
Set gcllimit = ['250']
WARNING: Waiting 5 seconds before retrying.
print(len(blpList))
2848
with open("fairuse-blp.txt", "w") as f:
    f.write("\n".join([blp[0].title() + "," + str(blp[1]) for blp in blpList]))