Year category intersection implemented

master
Castro0o 10 years ago
parent 6d421ccfc8
commit 8f3d66d8ac

@ -5,4 +5,4 @@ The process of creating a Website for MMD&C on the backend entails 4 steps:
* create JSON dictionary * create JSON dictionary
* create index * create index
* create pages * create pages
* (parse pages) * (parse pages

File diff suppressed because one or more lines are too long

@ -75,16 +75,36 @@ def parse_work_page(title, content):
work_dict[key]=val work_dict[key]=val
return work_dict return work_dict
def api_PageCategories(pageid):
'''Find all the categories, and their parent category of a page '''
query = 'action=query&pageids={}&prop=categories'.format(pageid)
url = endpoint + query
request = urllib2.urlopen(url)
jsonp = json.loads(request.read())
json_dic = jsonp['query']['pages']
page_id = json_dic.keys()[0]
page_categories = json_dic[page_id][u'categories']
all_cats = [ entry[u'title'].encode('utf-8') for entry in page_categories ] #.replace('Category:', '')
return all_cats
def api_category(category, year): #Find all pages incategory and add to allworks dictionary def api_category(category, year): #Find all pages incategory and add to allworks dictionary
''' TODO: category intersection; With SirrusSearch'''
category = category.replace(' ', '_') category = category.replace(' ', '_')
apiCatMembers = endpoint + 'action=query&list=categorymembers&cmlimit=1000&cmtitle=Category:{}'.format(category)
request = urllib2.urlopen(apiCatMembers)
jsonp = json.loads(request.read())
Graduation_work_Members = jsonp['query']['categorymembers']
intersectCatMembers = []
if year: if year:
api_url = endpoint + 'action=query&list=categorymembers&cmlimit=500&cmtitle=Category:{}&cmtitle=Category:{}'.format(category, year) for member in Graduation_work_Members:
page_cats = api_PageCategories(member['pageid'])
if ('Category:{}'.format(year)) in page_cats:
print year, 'in', page_cats
intersectCatMembers.append(member)# add member to intersectCatMembers
else: else:
api_url = endpoint + 'action=query&list=categorymembers&cmlimit=500&cmtitle=Category:{}'.format(category) intersectCatMembers = Graduation_work_Members
request = urllib2.urlopen(api_url)
jsonp = json.loads(request.read()) for page in intersectCatMembers:
for page in jsonp['query']['categorymembers']:
title = ((page['title']).encode('utf-8') ).replace(" ", "_") #snakecase for page titles title = ((page['title']).encode('utf-8') ).replace(" ", "_") #snakecase for page titles
pageid = page['pageid'] pageid = page['pageid']
article = api_page(pageid, 'content') article = api_page(pageid, 'content')

Loading…
Cancel
Save