def postissue(event, url, args): if str(args[0]).isdigit(): try: i = getissue(int(args[0])) msg = _('{} ({}) State: {}<br>{}').format(i["title"], i["number"], i["state"], i["link"]) except: msg = _('Invalid Issue Number') elif str(args[0]) == '--search': query = sanitize(' '.join(args[1:])) s = search(query) msg = _('Total Results: {}<br>First Result: {} ({})<br>State: {}<br>{}').format(s['total'], s['title'], s['number'], s['state'], s['link']) else: session = requests.Session() session.auth=(USERNAME, PASSWORD) # Create our issue issue = {'title': ' '.join(args), 'body': 'Issue created by {}'.format(event.user.full_name)} # Add the issue to our repository r = session.post(url, json.dumps(issue)) get = requests.get(url) data = json.loads(get.text) link = shorten(str(data[0][u'html_url'])) if r.status_code == 201: msg = _('Successfully created issue: {}').format(link) else: msg = _('Could not create issue.<br>Response: {}').format(r.content) return msg
def getlyrics(title, artist): response = get("https://musixmatchcom-musixmatch.p.mashape.com/wsr/1.1/track.search?f_has_lyrics=1&page=1&page_size=1&q_track=" + sanitize(title) + "&q_artist=" + sanitize(artist), headers={ "X-Mashape-Key": mashape, "Accept": "application/json" } ) data = json.loads(response.text) name = data[0]["track_name"] artst = data[0]["artist_name"] trackid = data[0]["track_id"] lyrget = get("https://musixmatchcom-musixmatch.p.mashape.com/wsr/1.1/track.lyrics.get?track_id=" + str(trackid), headers={ "X-Mashape-Key": mashape, "Accept": "application/json" } ) data2 = json.loads(lyrget.text) lyrics = data2["lyrics_body"] url = 'https://www.musixmatch.com/lyrics/' + artist.replace(" ", "-") + '/' + title.replace(" ", "-") return { 'name': name, 'artist': artst, 'lyrics': lyrics, 'url': url }