def save(): """ Save custom boards to db and return url """ uid = request.POST['uuid'] prefix_url = "http://multiboards.net/b/" infos = request.POST['urls'].replace('undefined', '') name = request.POST['name'] if uid and request.is_ajax: try: multiboards = Custom.get(Custom.uuid == uid) multiboards.name = name multiboards.infos = json.dumps(infos) multiboards.save() return prefix_url + multiboards.short except Exception: multiboards = Custom.create(name=name, uuid=uid, infos=json.dumps(infos), short='') # Create short url for custom multiboards url = url_encoding.encode_url(multiboards.id) multiboards.short = url # Save the custom multiboards multiboards.save() # Return short url of custom multiboards return prefix_url + url
def ressources(choice=None): """ <radios> return radios urls and names from settings RADIOS <sources> return sites sources to scan feed <news> return news to scan feed """ radios = _settings.RADIOS sources = _settings.SOURCES bottom_news = _settings.BOTTOM_NEWS bottom_line = _settings.BOTTOM_LINE imgur = _settings.IMGUR if choice == 'radios': # pick up radio list from setting # for now we are only playing ogg radios format radios = [] for playlist in radios: radios.append({'name': playlist[0], 'url': playlist[1]}) return json.dumps(radios) elif choice == 'sources': try: short_url = str(request.query['short_url']) except Exception as e: raise ValueError('no short url') # if we have a custom board if short_url != '' and short_url != 'Multiboards': try: # init sources sources = {} # get board infos req = Custom.get(Custom.id == url_encoding.decode_url(short_url)) sources[99] = req.name jsboards = json.loads(req.infos) # index boards boards = [None]*16 for board in eval(jsboards): index = board.split(';')[0].split(':')[1] boards[int(index)] = board # Replace default boards by custom # ["index:0;url:http://sametmax.com/feed/;header:#ac2626;odd:#ececec;even:#f2f2f2"] # for i in range(16): # if boards[i]: # bb = boards[i].split(';') # sources[i] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]] # else: # # plug the butt hole ! # sources[i] = ['', '','http://sametmax.com/feed/', 'ac2626','ececec', 'f2f2f2','', '','', '',] # print 'ko' #import ipdb;ipdb.set_trace() index = 0 for i in boards: try: index+=1 bb = i.split(';') sources[index] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]] except Exception as e: pass except Exception as e: print(e) raise 'Et merde!' return json.dumps(sources) elif choice == 'news': return json.dumps(bottom_news) elif choice == 'imgur': #return urllib.urlopen(imgur).read() pass elif choice == 'bottomline': return bottom_line[random.randrange(0, len(bottom_line))]
def ressources(choice=None): """ <radios> return radios urls and names from settings RADIOS <sources> return sites sources to scan feed <news> return news to scan feed """ radios = _settings.RADIOS sources = _settings.SOURCES bottom_news = _settings.BOTTOM_NEWS bottom_line = _settings.BOTTOM_LINE imgur = _settings.IMGUR if choice == 'radios': # pick up radio list from setting # for now we are only playing ogg radios format radios = [] for playlist in radios: radios.append({'name': playlist[0], 'url': playlist[1]}) return json.dumps(radios) elif choice == 'sources': try: short_url = unicode(request.query['short_url'], 'utf-8') except Exception, e: raise 'no short url' # if we have a custom board if short_url != '' and short_url != 'Multiboards': try: # init sources sources = {} # get board infos req = Custom.get(Custom.id == url_encoding.decode_url(short_url)) sources[99] = req.name jsboards = json.loads(req.infos) # index boards boards = [None]*16 for board in eval(jsboards): index = board.split(';')[0].split(':')[1] boards[int(index)] = board # Replace default boards by custom # ["index:0;url:http://sametmax.com/feed/;header:#ac2626;odd:#ececec;even:#f2f2f2"] # for i in range(16): # if boards[i]: # bb = boards[i].split(';') # sources[i] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]] # else: # # plug the butt hole ! # sources[i] = ['', '','http://sametmax.com/feed/', 'ac2626','ececec', 'f2f2f2','', '','', '',] # print 'ko' #import ipdb;ipdb.set_trace() index = 0 for i in boards: try: index+=1 bb = i.split(';') sources[index] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]] except Exception, e: pass except Exception as e: print e raise 'Et merde!' return json.dumps(sources)