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 load_quote_data(quote_keys):
    """ lookup quote data, from keys """
    print("Downloading: " + quote_keys['citing_url'])
    quote = QuoteLookup(
                quote_keys['citing_quote'],
                quote_keys['citing_url'],
                quote_keys['cited_url']
            )
    return quote.data()
Beispiel #4
0
def load_quote_data(quote_keys):
    """ lookup quote data, from keys """
    print("Downloading citation from: " + quote_keys['cited_url'])
    # print("  Downloading: " + quote_keys['citing_quote'])
    quote = QuoteLookup(
        quote_keys['citing_quote'],
        quote_keys['citing_url'],
        quote_keys['cited_url'],
        quote_keys['citing_text'],  # optional: caching
        quote_keys['citing_raw'],  # optional: caching
    )
    return quote.data()
Beispiel #5
0
    def citations(self):
        """ Returns a list of Quote Lookup results for all citations on this page
            Uses asycnronous pool to achieve parallel processing
            calls 'load_quote_data' function
            for all values in self.citations_list
            using python 'map' function
        """
        result_list = []
        for quote_keys in self.citations_list():
            print('Looking up: ' + quote_keys['cited_url'])
            quote = QuoteLookup(
                        quote_keys['citing_quote'],
                        quote_keys['citing_url'],
                        quote_keys['cited_url']
                    )
            result_list.append(quote.data())

        return result_list  # citations_data_list

        """
Beispiel #6
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 #7
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 #8
0
from neotext.lib.neotext_quote_context.quote import Quote

t0 = Quote(
    citing_quote="""<p>I am sick and tired of watching folks like Boris Johnson, Marine Le Pen, Donald Trump and others appeal to the worst racial instincts of our species, only to be shushed by folks telling me that it&#8217;s not <i>really</i> racism driving their popularity. It&#8217;s economic angst. It&#8217;s regular folks tired of being spurned by out-of-touch elites. It&#8217;s a natural anxiety over rapid cultural change.</p>

<p>Maybe it&#8217;s all those things. But at its core, it&#8217;s the last stand of old people who have been frightened to death by cynical right-wing media empires and the demagogues who enable them—all of whom have based their appeals on racism as overt as anything we&#8217;ve seen in decades. It&#8217;s loathsome beyond belief, and not something I thought I&#8217;d ever see in my lifetime. But that&#8217;s where we are.</p>""",
    citing_url='http://www.neotext.net/www.interfluidity.com/v2/6602.html',
    cited_url='http://www.motherjones.com/kevin-drum/2016/06/brexit-wins'
)
t0.hashkey()
t0.hash()


from neotext.lib.neotext_quote_context.quote import Quote
t2 = Quote(
    citing_quote="""
<p>I am sick and tired of watching folks like Boris Johnson, Marine Le Pen, Donald Trump and others appeal to the worst racial instincts of our species, only to be shushed by folks telling me that it&#8217;s not <i>really</i> racism driving their popularity. It&#8217;s economic angst. It&#8217;s regular folks tired of being spurned by out-of-touch elites. It&#8217;s a natural anxiety over rapid cultural change.</p>

<p>Maybe it&#8217;s all those things. But at its core, it&#8217;s the last stand of old people who have been frightened to death by cynical right-wing media empires and the demagogues who enable them—all of whom have based their appeals on racism as overt as anything we&#8217;ve seen in decades. It&#8217;s loathsome beyond belief, and not something I thought I&#8217;d ever see in my lifetime. But that&#8217;s where we are.</p>
""",

    citing_url='http://www.neotext.net/www.interfluidity.com/v2/6602.html',
    cited_url='http://www.motherjones.com/kevin-drum/2016/06/brexit-wins'
)
t2.hashkey()
t2.hash()