This repository has been archived by the owner on Dec 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMoeGirlWiki.py
58 lines (49 loc) · 1.8 KB
/
MoeGirlWiki.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# coding: utf-8
'''
Created on 2013-8-7
http://zh.moegirl.org/api.php?format=json&action=query&list=search&srwhat=title&srsearch=%E5%A4%8F%E5%A8%9C&srlimit=10
http://zh.moegirl.org/api.php?format=json&action=query&list=search&srwhat=text&srsearch=%E5%A8%9C
@author: xuechong
'''
from utils.Commons import fetchContentFromUrl
import json
import logging
import urllib
_wikiurl = "http://zh.moegirl.org/api.php?format=json&action=query&list=search&srwhat=title&srsearch=$title&srlimit=$limit"
cleancontent = lambda x:x.replace("<span class='searchmatch'>", "").replace("</span>", "")
class WikiContent(object):
title=""
snippet=""
size=""
wordcount=""
timestamp=""
def searchTitle(title,size=10):
result = list()
url = _wikiurl.replace("$title", urllib.quote(title)).replace("$limit", "10")
logging.info(url)
remoteResult = fetchContentFromUrl(url)
allSubjects=json.loads(remoteResult)["query"]["search"]
for subject in allSubjects:
content = WikiContent()
content.title = cleancontent(subject["title"])
content.snippet = cleancontent(subject["snippet"])
content.size = subject["size"]
content.wordcount = subject["wordcount"]
content.timestamp = subject["timestamp"]
result.append(content)
return result
#if __name__ == '__main__':
# remoteResult = fetchContentFromUrl(_wikiurl.replace("$title", "夏娜").replace("$limit", "10"))
# print remoteResult + "\n"
# result = json.loads(remoteResult)
# allSubjects=result["query"]["search"]
# for subject in allSubjects:
# print "title=" + cleancontent(subject["title"]) + "\n"
# print "snippet=" + cleancontent(subject["snippet"]) + "\n"
# print "timestamp=" + str(subject["timestamp"]) + "\n"
#
#
#
#
#
# pass