-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkural.py
81 lines (69 loc) · 2.99 KB
/
kural.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
query ='now'
_author_ = "Rk"
_pyversion_ = "2.7 or lower"
import os,re,ast
import sys
import bs4
import requests
import logging
import ast,json,yaml,sqlite3
def search(query):
url='http://api.gokulnath.com/thirukkuralchapters/5/thirukkurals'
## url = 'http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias' \
## '%3Daps&field-ke#ywords={}'.format(query.replace(' ', '+'))
return scrape(url)
print (url)
def scrape(url):
response = requests.get(url,
headers={'User-agent': 'Mozilla/5.0 (Windows NT '
'6.2; WOW64) AppleWebKit/'
'537.36 (KHTML, like '
'Gecko) Chrome/37.0.2062.'
'120 Safari/537.36'})
rk=response.content
#rk = "\n".join(rk.split("<br />"))
d = yaml.load(rk)
#### for tag in d['Data']:
#### print tag['Index']
## print tag['English']
## print "\n".join(tag['English'].split("<br />"))
## print '\n'
## print "\n".join(tag['Tamil'].split("<br />"))# replacing break statement with new line statement
## print "\n".join(tag['English'].split("<br />"))
## print "\n".join(tag['KalaignarUrai'].split("<br />"))
##['Index', 'Tamil', 'EnglishMeaning', 'English', 'KalaignarUrai', 'SolomonPaapaiyaUrai', 'TamilTransliteration']
conn = sqlite3.connect('rk.db')
cursor = conn.cursor()
print "Opened database successfully"
for i,tag in enumerate (d['Data']):
item = [
tag['Index'],
tag['Tamil'],
tag['EnglishMeaning'],
tag['English'],
tag['KalaignarUrai'],
tag['SolomonPaapaiyaUrai'],
tag['TamilTransliteration'],
]
print item[4]
#### print str(i)+,tag['Index'],tag['English'],tag['EnglishMeaning']',tag['EnglishMeaning'],tag['EnglishMeaning'],tag['EnglishMeaning'],tag['EnglishMeaning'])
#### cursor.execute("INSERT INTO KURAL (ID,ADIKAR,TAMIL,ENGLISH,MUVAURAI,KALAURAI,SOLOURAI,TAMTRANS)VALUES ("+str(i)+",'look','look','look','look','look','look','look')")
#### cursor.execute("INSERT INTO KURAL VALUES (NULL,"+str(tag['Index'])+
#### ","+str(tag['Index'])+
#### ","+str(tag['Index'])+
#### ","+str(tag['Index'])+
#### ","+str(tag['Index'])+
#### ","+str(tag['Index'])+
#### ","+str(tag['Index'])+
#### ")")
## query="INSERT INTO KURAL VALUES (NULL,?,?,?,?,?,?,?)"
## cursor.execute(query,item)
##
## conn.commit()
## conn.close()
##
#### conn.commit()
###### cursor = conn.execute("SELECT * from KURAL")
###### for row in cursor:
###### print row
search('now')