Skip to content

Instantly share code, notes, and snippets.

@HarHar
Created November 16, 2013 01:19
Show Gist options
  • Save HarHar/7494578 to your computer and use it in GitHub Desktop.
Save HarHar/7494578 to your computer and use it in GitHub Desktop.
Converts MAL entries to ANN entries on Futaam Put it on ..../Futaam/interfaces/fix.py Run "futaam --fix yourdbfile"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
try:
import readline
except ImportError:
print "Module readline unavailable."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
import os
import sys
from interfaces.common.utils import colors
from interfaces.common.parser import Parser
import interfaces.common.utils as utils
COLORS = colors()
COLORS.enable()
ANN = utils.ANNWrapper()
ANNInitRet = ANN.init()
if ANNInitRet == 0:
pass
elif ANNInitRet == 1:
print COLORS.header + 'Updating metadata...' + COLORS.default
ANN.fetchReport(50)
elif ANNInitRet == 2:
print COLORS.header + 'Updating ANN metadata cache for the first time...' + COLORS.default
ANN.fetchReport('all')
def main(argv):
dbfile = argv[0]
db = Parser(dbfile)
for i, item in enumerate(db.dictionary['items']):
if item['type'] == 'vn': continue
print ''
print COLORS.header + 'Working on item "' + item['name'] + '"' + COLORS.default + ' [' + str(i) + '/' + str(len(db.dictionary['items'])) + ']'
aux = True
name = item['name']
online = False
while aux:
try:
results = ANN.search(name, item['type'], online)
if len(results) == 0:
print 'No match on DB'
print 'Pick an option:'
print '1) Search with same name online'
print '2) Choose a different name'
opt = ''
while opt.isdigit() == False:
opt = raw_input('> ').replace('\n', '').replace(' ', '')
opt = int(opt)
if opt == 1:
online = True
elif opt == 2:
name = raw_input(COLORS.bold + 'New name> ' + COLORS.default)
else:
print 'Invalid option'
else:
assume = False
if assume:
if len(results) == 1:
print 'Assuming only result: "' + results[0]['title'] + '"'
item['aid'] = picked['id']
aux = False
continue
i = 0
for result in results:
print '[' + str(i) + '] ' + result['title']
i += 1
print '[O] Search with the same name online'
print '[N] Choose a different name'
picked = raw_input(COLORS.bold + 'Pick one> ' + COLORS.default).replace('\n', '').replace(' ', '')
if picked.lower() == 'o':
online = True
continue
elif picked.lower() == 'n':
name = raw_input(COLORS.bold + 'New name> ' + COLORS.default)
continue
elif picked.isdigit():
picked = results[int(picked)]
else:
print 'Invalid option'
item['aid'] = picked['id']
aux = False
except KeyboardInterrupt:
exit()
except Exception, e:
print 'Exception ocurred, assuming it\'s ok to continue (' + str(e) + ')'
continue
print 'FUCKING DONE!!!!!!!!!!!!!!!!!!!!!'
print 'Saving...'
db.save()
print 'Saved'
print 'bye bye'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment