forked from Freso/musicbrainz-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
end_bbc.py
57 lines (47 loc) · 1.99 KB
/
end_bbc.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
# -*- coding: utf-8 -*-
from optparse import OptionParser
import sqlalchemy
import mechanize
from editing import MusicBrainzClient
from mbbot.utils.pidfile import PIDFile
import config as cfg
engine = sqlalchemy.create_engine(cfg.MB_DB)
db = engine.connect()
db.execute('SET search_path TO musicbrainz')
mb = MusicBrainzClient(cfg.MB_USERNAME, cfg.MB_PASSWORD, cfg.MB_SITE)
query_http_rels = sqlalchemy.text('''
SELECT url.url, url.gid AS url_gid, artist.gid AS artist_gid, l_au.id, l.link_type FROM url
JOIN l_artist_url l_au ON url.id = l_au.entity1
JOIN link l ON l.id = l_au.link
JOIN artist ON artist.id = l_au.entity0
WHERE l_au.edits_pending = 0
AND url LIKE 'https://www.bbc.co.uk/music/artists/%'
AND l.ended = FALSE
LIMIT 1000
''')
browser = mechanize.Browser()
browser.set_handle_robots(False)
browser.set_debug_redirects(False)
browser.set_debug_http(False)
def main(verbose = False):
edit_note = """BBC Music artist pages were switched off on Nov 19, 2020. See https://tickets.metabrainz.org/browse/MBBE-28"""
if verbose:
print 'Finding relationships using SQL query:', query_http_rels
rels = db.execute(query_http_rels)
if verbose:
print u'Found %s relationships!' % (rels.rowcount)
for rel in rels:
entity0 = {'type': 'url', 'gid': rel['url_gid'], 'url': rel['url']}
entity1 = {'type': 'artist', 'gid': rel['artist_gid']}
endDate = {'year': 2020, 'month': 11, 'day': 19}
if verbose:
print u'[!!!] Working on url: %s' % (cfg.MB_SITE + u'/url/' + unicode(rel['url_gid']))
print u'URL is: %s' % (unicode(rel['url']))
mb.edit_relationship(rel['id'], entity0, entity1, rel['link_type'], {}, {}, endDate, True, edit_note, True)
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('-v', '--verbose', action='store_true', default=True,
help='be more verbose')
(options, args) = parser.parse_args()
with PIDFile('/tmp/mbbot_end_bbc.pid'):
main(options.verbose)