-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler_nurkz.py
executable file
·50 lines (42 loc) · 1.85 KB
/
crawler_nurkz.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
#!/bin/env python3
import sys
import mysql.connector as mysql
import requests
apiInit = requests.get('http://nota.kg/api/nurkz/index.php', auth=('marat', 'marat'))
if apiInit.status_code != 200:
print('Cannot initialize nurkz API.')
sys.exit(1)
jsonReq = requests.get('http://nota.kg/api/nurkz/result.json', auth=('marat', 'marat'))
if jsonReq.status_code !=200:
print('Cannot get results.json file.')nmjk,.,mj
sys.exit(1)
jsonData = jsonReq.json()
con = mysql.connect(host='127.0.0.1', user='root', password='Not@db', database='nota')
cur = con.cursor(buffered=True)
con.set_charset_collation('utf8')
cur.execute('SET NAMES utf8;')
cur.execute('SET CHARACTER SET utf8;')
cur.execute('SET character_set_connection=utf8;')
for song in jsonData['list']:
songUrl = song['url'].strip()
for artistStr in song['artist']:
artist = artistStr.strip()
title = song['song']
cur.execute("select id from vass_artists where name = %s;", (artist,))
artistId = cur.fetchone()
if artistId is None:
print(artist)
cur.execute("insert into vass_artists (name, tag, bio, follow, link) values(%s, '', %s, 0, '');", (artist,artist))
artistId = int(cur.lastrowid)
else:
artistId = artistId[0]
cur.execute("select count(1) from vass_songs where url = %s and artist_id = %s;", (songUrl, artistId))
if cur.fetchone()[0] == 0:
print ('\t' + title)
cur.execute("""\
insert into vass_songs(recent, song_country, user_id, created_on, url, artist_id, title, album_id, tags, lyrics, artists_id, last_loved, fav, played, purchase_url, permalink_url)
values(1, 116, 1, sysdate(), %s, %s, %s, 0, '', '', '', sysdate(), 0, 0, '', '');
""",(songUrl, artistId, title)
)
cur.close()
con.close()