<s> from . import contexts <EOL> from . import util <EOL> from . models import Venue <EOL> from . views import geo_name <EOL> from bs4 import BeautifulSoup <EOL> from flask import request , jsonify , redirect , url_for , Blueprint , current_app , render_template <EOL> import datetime <EOL> import mf2py <EOL> import mf2util <EOL> import requests <EOL> import sys <EOL> import urllib <EOL> services = Blueprint ( '<STR_LIT>' , __name__ ) <EOL> USER_AGENT = '<STR_LIT>' <EOL> @ services . route ( '<STR_LIT>' ) <EOL> def fetch_profile ( ) : <EOL> url = request . args . get ( '<STR_LIT:url>' ) <EOL> if not url : <EOL> return """<STR_LIT>""" <EOL> try : <EOL> name = None <EOL> image = None <EOL> d = mf2py . Parser ( url = url ) . to_dict ( ) <EOL> relmes = d [ '<STR_LIT>' ] . get ( '<STR_LIT>' , [ ] ) <EOL> hfeed = next ( ( item for item in d [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in item [ '<STR_LIT:type>' ] ) , None ) <EOL> if hfeed : <EOL> authors = hfeed . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> images = hfeed . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> if authors : <EOL> if isinstance ( authors [ <NUM_LIT:0> ] , dict ) : <EOL> name = authors [ <NUM_LIT:0> ] . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT:name>' ) <EOL> image = authors [ <NUM_LIT:0> ] . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> else : <EOL> name = authors [ <NUM_LIT:0> ] <EOL> if images and not image : <EOL> image = images [ <NUM_LIT:0> ] <EOL> for item in d [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in item . get ( '<STR_LIT:type>' , [ ] ) : <EOL> if not name : <EOL> name = item . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT:name>' ) <EOL> if not image : <EOL> image = item . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> return jsonify ( { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:image>' : image , <EOL> '<STR_LIT>' : relmes , <EOL> } ) <EOL> except BaseException as e : <EOL> resp = jsonify ( { '<STR_LIT:error>' : str ( e ) } ) <EOL> resp . status_code = <NUM_LIT> <EOL> return resp <EOL> @ services . route ( '<STR_LIT>' ) <EOL> def nearby_venues ( ) : <EOL> lat = float ( request . args . get ( '<STR_LIT>' ) ) <EOL> lng = float ( request . args . get ( '<STR_LIT>' ) ) <EOL> venues = Venue . query . all ( ) <EOL> venues . sort ( key = lambda venue : ( float ( venue . location [ '<STR_LIT>' ] ) - lat ) ** <NUM_LIT:2> <EOL> + ( float ( venue . location [ '<STR_LIT>' ] ) - lng ) ** <NUM_LIT:2> ) <EOL> return jsonify ( { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:id>' : venue . id , <EOL> '<STR_LIT:name>' : venue . name , <EOL> '<STR_LIT>' : venue . location [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : venue . location [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : geo_name ( venue . location ) , <EOL> } for venue in venues [ : <NUM_LIT:10> ] ] <EOL> } ) <EOL> @ services . route ( '<STR_LIT>' ) <EOL> def fetch_context_service ( ) : <EOL> results = [ ] <EOL> for url in request . args . getlist ( '<STR_LIT>' ) : <EOL> ctx = contexts . create_context ( url ) <EOL> results . append ( { <EOL> '<STR_LIT:title>' : ctx . title , <EOL> '<STR_LIT>' : ctx . permalink , <EOL> '<STR_LIT:html>' : render_template ( <EOL> '<STR_LIT>' , type = request . args . get ( '<STR_LIT:type>' ) , <EOL> context = ctx ) , <EOL> } ) <EOL> return jsonify ( { '<STR_LIT>' : results } ) <EOL> @ services . route ( '<STR_LIT>' ) <EOL> def youtube_shortener ( video , slug ) : <EOL> return redirect ( '<STR_LIT>' . format ( video ) ) <EOL> @ services . route ( '<STR_LIT>' ) <EOL> def create_youtube_link ( ) : <EOL> url = request . args . get ( '<STR_LIT:url>' ) <EOL> if url : <EOL> m = util . YOUTUBE_RE . match ( url ) <EOL> if m : <EOL> video_id = m . group ( <NUM_LIT:1> ) <EOL> resp = requests . get ( url ) <EOL> soup = BeautifulSoup ( resp . text ) <EOL> title = soup . find ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) . get ( '<STR_LIT:content>' ) <EOL> if title : <EOL> url = url_for ( '<STR_LIT>' , video = video_id , slug = util . slugify ( title ) , _external = True ) <EOL> return """<STR_LIT>""" . format ( url , url ) <EOL> return """<STR_LIT>""" </s>
