Exemple #1
0
def get_latest_tags(url):
    #something to use for downloading
    opener = urllib2.build_opener()
    #the latest exif tag spec
    response = opener.open(url)
    #the html
    html = response.read().replace('\n','')
    response.close()
    #get the first mention of the 'Exif' table
    tableStart = -1
    while len(html) > 0:
        #begin tag
        start = html.find('<table')
        if start == -1:
            break
        #end tag
        end = html.find('>', start) + 1
        if end == -1:
            break
        #entire declaration
        tableDecl = html[start : end]
        #this is the right one
        if 'Exif' in tableDecl:
            tableStart = start
            break
        else:
            html =  html[end : ]

    #if we found the beginning of the tags
    if tableStart != -1:
        #find the end tag
        tableEnd = html.find('</table', tableStart)
        if tableEnd != -1:
            tableEnd = html.find('>', tableEnd) + 1
            if tableEnd != -1:
                html = html[tableStart : tableEnd]
            else:
                html = ''
        else:
            html = ''

    #grab the body
    body = html[html.find('<tbody') : html.find('>', html.find('</tbody')) + 1]

    #if we have a table we need to parse it
    tags = {}
    if len(body) > 0:
        #pretend its xml and load it into a dict
        rows = xml_to_dict(body)
        for row in rows['tr']:
            columns = row['td']
            #get the tag id number and save the tag name
            tags[int(columns[1]['v'])] = columns[3]['v']

    #give the tags back
    return tags
Exemple #2
0
 def __init__(self, response):
     self._xml = response
     self._dict = xml_to_dict(response)
     _extend(self, self._dict.values()[0])