Ejemplo n.º 1
0
def search(query, api_key, limit=10):
    """Yield search results item by item"""
    page_size = _page_size(limit)
    dpla = DPLA(api_key)
    page = 0
    yielded = 0
    while yielded < limit:
        page += 1
        result = dpla.search(query,
                             page_size=page_size,
                             page=page,
                             fields=['sourceResource'])
        if len(result.items):
            for item in result.items:
                yield item
                yielded += 1
        else:
            raise StopIteration
Ejemplo n.º 2
0
    def on_status(self, status):

        # get data from tweet

        querier = status.author.screen_name
        twt = status.text
        twt_term = twt.replace("@QueryDPLA ", "")

        # search DPLA

        dpla = DPLA('xxxxx')  # your DPLA API key
        result = dpla.search(q="%s" % twt_term,
                             fields=["sourceResource.title", "id"],
                             page_size=50)

        # pick random result

        total = result.count

        if total > 49:
            json_data = result.items[random.randint(0, 49)]
        elif total in range(1, 50):
            json_data = result.items[random.randint(0, (total - 1))]
        else:
            pass

        # tweet DPLA metadata at querier

        if total >= 1:
            title = json_data['sourceResource.title']
            json_id = json_data['id']
            item_url = 'http://dp.la/item/%s' % json_id

            api.update_status(".@%s %s %s" % (querier, title[:80], item_url),
                              in_reply_to_status_id=status.id)
        else:
            api.update_status(".@%s No items found. Try another term!" %
                              querier,
                              in_reply_to_status_id=status.id)
Ejemplo n.º 3
0
from dpla.api import DPLA
#how to access your 'API_KEY' so you don't have to enter every time
#os lets you look at your computer
import os
#pull your API_KEY
my_api_key = '6fe82fec460e727f153f50b9e6b28e07'
#open a connection with the DPLA API.
dpla_connection = DPLA(my_api_key)

#use requests library
import requests

#add an endpoint where we can make requests
endpoint = 'https://api.dp.la/v2/items'
#set parameters to get information about Austi, Texas
params = {
    'api_key': my_api_key,
    'q': "Austin, Texas",
}
#let's get the requests back!
requested_the_hard_way = requests.get(endpoint, params)
requested_the_hard_way.status_code
#print the URL
print("****")
print(requested_the_hard_way.url)
#print the number of results
print("****")
print(requested_the_hard_way.json()['count'])
#print the 'docs'(?) for the first page of results
print("****")
print(requested_the_hard_way.json()['docs'][0])
Ejemplo n.º 4
0
from dpla.api import DPLA

dpla = DPLA('your_key_here')

fields = {"sourceResource.type": "image"}

search_query = '"fourth of july" OR "independence day" OR "July 4th" OR "July Fourth"'

result = dpla.search(search_query, searchFields=fields, page_size=10000)

print(result.count)

with open('ids.csv', "w") as f:
    for x in result.all_records():
        f.write(x['id'] + "\n")
Ejemplo n.º 5
0
import tweepy, random
from dpla.api import DPLA 
from credentials import *

#authenticate with Twitter api using credentials.py
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

#create DPLA object using dpla module and your API key
dpla = DPLA(DPLA_KEY)

def send_tweet():
  #generate random number to use as page value
  random_page = random.randint(0, 100)
  
  #create results set of all DPLA items where provider is SSDN 
  fields = {"provider" : "Sunshine State Digital Network"}
  result = dpla.search(searchFields=fields, page_size=100, page=random_page)

  #get random item from the results
  items = random.sample(result.items, 1)

  #print the id of the random item to the console - used for testing
  #print(items[0]["id"])

  #extract element from the record to use in tweet
  for item in items:
  #determine if description field is present, and compose tweety accordingly
    if "description" in item["sourceResource"]:
      url = "https://dp.la/item/" + item["id"]
Ejemplo n.º 6
0
from dpla.api import DPLA
from unscroll import UnscrollClient
import pprint
import datefinder

dpla = DPLA('d858a6fc387cfe9eebf702fca43c9798')
result = dpla.search(q="raccoon", page_size=10)

i = 0
for item in result.all_records():
    i = i + 1
    if i > 20:
        break
    r = item
    pprint.pprint(r)

    dt = None
    date = r.get('date')
    if date is not None and type(date) is list:
        date = date[0]
        print('XXXXX', date)
    if date is not None:
        disp_date = date.get('displayDate')
        if disp_date is not None:
            print('DISP_DATE', disp_date)
            dt = None
            dates = list(datefinder.find_dates(disp_date))
            if len(dates) > 0:
                dt = dates[0]
    print('DTDT', dt)
    if dt is not None: