Beispiel #1
0
def demo(request):
    """
    citing_quote = request.POST.get('citing_quote',"I was told on the phone — I forget by whom — that my good friend Roger Gregory, who was in charge at XOC down south in Palo Alto, was throwing things and acting crazy. I heard that ‘everybody was ready to leave,’ possibly quit within a day or so.")
    citing_url = request.POST.get('citing_url',"http://www.openpolitics.com/2015/09/06/ted-nelson-philosophy-of-hypertext/")
    cited_url = request.POST.get('cited_url',"http://www.openpolitics.com/links/possiplex-ted-nelson-pg-261/")

    post_values = {'citing_quote' : citing_quote,
        'citing_url' : citing_url,
        'cited_url' : cited_url
    }

    #url = 'http://db.neotext.net/quote/'
    url = 'http://neotext.webfactional.com/quote/'

    data = parse.urlencode(post_values)
    data = data.encode('utf-8') # data should be bytes
    req = urllib.request.Request(url, data)
    with urllib.request.urlopen(req) as response:
        json = response.read()
    """

    citing_quote = 'The experience of writing it was one of the most intense I have ever experienced, in an exalted state of excitement and inspiration.The same epiphany I had experienced at the age of five, of the immensity and indescribability of the world, came to me again, but this time with regard to realizing how models and language and thought worked, a way of approaching the great complexity I had envisioned long before.'
    citing_url = 'http://www.openpolitics.com/2015/09/06/ted-nelson-philosophy-of-hypertext/'
    cited_url = 'http://www.openpolitics.com/links/philosophy-of-hypertext-by-ted-nelson-page-48/'

    q = QuoteLookup(citing_quote, citing_url, cited_url)
    json = q.json()
    """
    """
    return HttpResponse(json, content_type='application/json', status=201) # 201=created
Beispiel #2
0
def demo(request):
    """
    citing_quote = request.POST.get('citing_quote',"I was told on the phone — I forget by whom — that my good friend Roger Gregory, who was in charge at XOC down south in Palo Alto, was throwing things and acting crazy. I heard that ‘everybody was ready to leave,’ possibly quit within a day or so.")
    citing_url = request.POST.get('citing_url',"http://www.openpolitics.com/2015/09/06/ted-nelson-philosophy-of-hypertext/")
    cited_url = request.POST.get('cited_url',"http://www.openpolitics.com/links/possiplex-ted-nelson-pg-261/")

    post_values = {'citing_quote' : citing_quote,
        'citing_url' : citing_url,
        'cited_url' : cited_url
    }

    #url = 'http://db.neotext.net/quote/'
    url = 'http://neotext.webfactional.com/quote/'

    data = parse.urlencode(post_values)
    data = data.encode('utf-8') # data should be bytes
    req = urllib.request.Request(url, data)
    with urllib.request.urlopen(req) as response:
        json = response.read()
    """

    citing_quote = 'The experience of writing it was one of the most intense I have ever experienced, in an exalted state of excitement and inspiration.The same epiphany I had experienced at the age of five, of the immensity and indescribability of the world, came to me again, but this time with regard to realizing how models and language and thought worked, a way of approaching the great complexity I had envisioned long before.'
    citing_url = 'http://www.openpolitics.com/2015/09/06/ted-nelson-philosophy-of-hypertext/'
    cited_url = 'http://www.openpolitics.com/links/philosophy-of-hypertext-by-ted-nelson-page-48/'

    q = QuoteLookup(citing_quote, citing_url, cited_url)
    json = q.json()
    """
    """
    return HttpResponse(json, content_type='application/json', status=201) # 201=created
Beispiel #3
0
def quote_json(request, sha1=None):
    """ Lookup context from POSTed quote and url
    Save resulting json file to Amazon S3

    Reads should be done from amazon S3:
    Example:  http://read.neotext.net/quote/sha1/v0.02/sha1_hash
    """
    ACCEPT_READ_REQUESTS = True
    data_dict = {}  # quote context data
    data = {}
    if len(request.POST) == 0:
        if not ACCEPT_READ_REQUESTS:
            return HttpResponse(status=401) # bad request
        else:
            if sha1:
                data_dict = get_quote_dict_from_sha(sha1)

                if data_dict: # test
                    data = json.dumps(data_dict)
                    return HttpResponse(data, content_type='application/json', \
                        status=201) #201=created
                else:
                    raise Http404
    else:
        citing_quote = request.POST.get('citing_quote','')
        citing_quote = citing_quote.strip()
        citing_url = request.POST.get('citing_url','')
        cited_url = request.POST.get('cited_url', '')

        if len(citing_quote) == 0:
            return HttpResponse(status=400) # bad request

        if ( not(is_url(citing_url)) or not(is_url(cited_url)) ):
            return HttpResponse(status=400) # bad request

        #Create Quote Record, By Downloading cited URL
        q = QuoteLookup(citing_quote, citing_url, cited_url)
        data_dict = q.dict()

        if 'error' in data_dict:
            raise Http404

        # Save result to database
        try:
            quote = Quote(**data_dict)
            quote.save()

        except (IntegrityError, DatabaseError, ProgrammingError) as e:
            raise
            return HttpResponse(status=409) # conflict

        filename = ''.join([data_dict['sha1'],'.json'])
        local_filename = ''.join([JSON_FILE_PATH, filename])
        data = q.json()

        with open(local_filename, 'w') as outfile:
            json.dump(data, outfile, indent=4, ensure_ascii=False)

        save_json_to_cloud(filename, local_filename)

    return HttpResponse(data, \
        content_type='application/json', status=201) # 201=created
Beispiel #4
0
def quote_json(request, sha1=None):
    """ Lookup context from POSTed quote and url
    Save resulting json file to Amazon S3

    Reads should be done from amazon S3:
    Example:  http://read.neotext.net/quote/sha1/v0.02/sha1_hash
    """
    ACCEPT_READ_REQUESTS = True
    data_dict = {}  # quote context data
    data = {}
    if len(request.POST) == 0:
        if not ACCEPT_READ_REQUESTS:
            return HttpResponse(status=401) # bad request
        else:
            if sha1:
                data_dict = get_quote_dict_from_sha(sha1)

                if data_dict: # test
                    data = json.dumps(data_dict)
                    return HttpResponse(data, content_type='application/json', \
                        status=201) #201=created
                else:
                    raise Http404
    else:
        citing_quote = request.POST.get('citing_quote','')
        citing_quote = citing_quote.strip()
        citing_url = request.POST.get('citing_url','')
        cited_url = request.POST.get('cited_url', '')

        if len(citing_quote) == 0:
            return HttpResponse(status=400) # bad request

        if ( not(is_url(citing_url)) or not(is_url(cited_url)) ):
            return HttpResponse(status=400) # bad request

        #Create Quote Record, By Downloading cited URL
        q = QuoteLookup(citing_quote, citing_url, cited_url)
        data_dict = q.dict()

        if 'error' in data_dict:
            raise Http404

        # Save result to database
        try:
            quote = Quote(**data_dict)
            quote.save()

        except (IntegrityError, DatabaseError, ProgrammingError) as e:
            raise
            return HttpResponse(status=409) # conflict

        filename = ''.join([data_dict['sha1'],'.json'])
        local_filename = ''.join([JSON_FILE_PATH, filename])
        data = q.json()

        with open(local_filename, 'w') as outfile:
            json.dump(data, outfile, indent=4, ensure_ascii=False)

        save_json_to_cloud(filename, local_filename)

    return HttpResponse(data, \
        content_type='application/json', status=201) # 201=created