Drop python2 support.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/15/head r14.1.0
Michele Calgaro 2 years ago
parent 8293cbe189
commit 900386ad46
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -15,7 +15,7 @@
### along with this program; if not, write to the Free Software ### along with this program; if not, write to the Free Software
### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import urllib, re,string import urllib.request, urllib.parse, urllib.error, re,string
################################################################################ ################################################################################
# Groups of interest # Groups of interest
@ -29,7 +29,7 @@ articleBase = "http://www.fyens.dk/"
# Query the sections # Query the sections
################################################################################ ################################################################################
def readSections(): def readSections():
FILE=urllib.urlopen(base+"Menu.php") FILE=urllib.request.urlopen(base+"Menu.php")
REG=re.compile("<a href=\"([^\"]*)\" target=\"Indhold\" class=\"Overskrift.\">(.*?)</a><br>") REG=re.compile("<a href=\"([^\"]*)\" target=\"Indhold\" class=\"Overskrift.\">(.*?)</a><br>")
result=[] result=[]
line=FILE.readline() line=FILE.readline()
@ -46,20 +46,20 @@ def readSections():
# Fetch articles from a single section # Fetch articles from a single section
################################################################################ ################################################################################
def readSection( url, title ): def readSection( url, title ):
FILE=urllib.urlopen(base+url) FILE=urllib.request.urlopen(base+url)
REG=re.compile("<a href=\"([^\"]*)\" class=\"Overskrift.\">(.*?)</a>") REG=re.compile("<a href=\"([^\"]*)\" class=\"Overskrift.\">(.*?)</a>")
line = FILE.readline() line = FILE.readline()
while line: while line:
match = REG.search(line) match = REG.search(line)
if match: if match:
print "<item>\n\t<title>" + title + ": " +match.group(2) + "</title>" print("<item>\n\t<title>" + title + ": " +match.group(2) + "</title>")
print "\t<link>"+articleBase+match.group(1)+"</link>\n</item>" print("\t<link>"+articleBase+match.group(1)+"</link>\n</item>")
line=FILE.readline() line=FILE.readline()
################################################################################ ################################################################################
# Print Header # Print Header
################################################################################ ################################################################################
print """<?xml version="1.0" encoding="ISO-8859-1"?> print("""<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
"http://my.netscape.com/publish/formats/rss-0.91.dtd"> "http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91"> <rss version="0.91">
@ -68,7 +68,7 @@ print """<?xml version="1.0" encoding="ISO-8859-1"?>
<language>dk</language> <language>dk</language>
<link>http://www.fyens.dk/</link> <link>http://www.fyens.dk/</link>
<description>Fyens Stiftstidende</description> <description>Fyens Stiftstidende</description>
""" """)
################################################################################ ################################################################################
# Main # Main
@ -81,8 +81,8 @@ for (url, title) in l:
################################################################################ ################################################################################
# Print footer. # Print footer.
################################################################################ ################################################################################
print """ print("""
</channel> </channel>
</rss> </rss>
""" """)

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import string, urllib, sys import string, urllib.request, urllib.parse, urllib.error, sys
if len(sys.argv) > 1: if len(sys.argv) > 1:
sport = sys.argv[1] sport = sys.argv[1]
@ -8,21 +8,21 @@ else:
class SportsParser: class SportsParser:
def __init__(self): def __init__(self):
print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" print("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>")
print "<rdf:RDF" print("<rdf:RDF")
print "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" print("xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"")
print "xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">" print("xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">")
print "<channel>" print("<channel>")
print "<title>%s</title>" %self.title() print("<title>%s</title>" %self.title())
print "<description>%s</description>" %self.description() print("<description>%s</description>" %self.description())
print "<link>%s</link>" %self.link() print("<link>%s</link>" %self.link())
print "</channel>" print("</channel>")
self.processScores(self.inputFile()) self.processScores(self.inputFile())
print "</rdf:RDF>" print("</rdf:RDF>")
def processScores(self, inputFile): def processScores(self, inputFile):
try: try:
input = urllib.urlopen(self.inputFile()) input = urllib.request.urlopen(self.inputFile())
lines = input.readlines() lines = input.readlines()
except: except:
sys.exit(5) sys.exit(5)
@ -32,10 +32,10 @@ class SportsParser:
self.handleScoreLine(line) self.handleScoreLine(line)
def handleGame(self, headline, link): def handleGame(self, headline, link):
print "<item>" print("<item>")
print "<title>%s</title>" %headline print("<title>%s</title>" %headline)
print "<link>%s</link>" %link print("<link>%s</link>" %link)
print "</item>" print("</item>")
class NHLParser(SportsParser): class NHLParser(SportsParser):
def isScoreLine(self, line): def isScoreLine(self, line):
@ -235,7 +235,7 @@ try:
parser = globals()["%sParser" %(sport)]() parser = globals()["%sParser" %(sport)]()
except: except:
print "Invalid sport type '%s' selected." %sport print("Invalid sport type '%s' selected." %sport)
sys.exit(2) sys.exit(2)
sys.exit(0) sys.exit(0)

@ -97,7 +97,7 @@ EXIF_TAGS={
0x010F: ('Make', ), 0x010F: ('Make', ),
0x0110: ('Model', ), 0x0110: ('Model', ),
0x0111: ('StripOffsets', ), 0x0111: ('StripOffsets', ),
0x0112: ('Qt::Orientation', ), 0x0112: ('Orientation', ),
0x0115: ('SamplesPerPixel', ), 0x0115: ('SamplesPerPixel', ),
0x0116: ('RowsPerStrip', ), 0x0116: ('RowsPerStrip', ),
0x0117: ('StripByteCounts', ), 0x0117: ('StripByteCounts', ),
@ -631,7 +631,7 @@ MAKERNOTE_CANON_TAG_0x004={
def s2n_motorola(str): def s2n_motorola(str):
x=0 x=0
for c in str: for c in str:
x=(long(x) << 8) | ord(c) x=(int(x) << 8) | ord(c)
return x return x
# extract multibyte integer in Intel format (big endian) # extract multibyte integer in Intel format (big endian)
@ -707,7 +707,7 @@ class EXIF_header:
val=s2n_motorola(slice) val=s2n_motorola(slice)
# Sign extension ? # Sign extension ?
if signed: if signed:
msb=1L << (8*length-1) msb=1 << (8*length-1)
if val & msb: if val & msb:
val=val-(msb << 1) val=val-(msb << 1)
return val return val
@ -750,8 +750,7 @@ class EXIF_header:
field_type=self.s2n(entry+2, 2) field_type=self.s2n(entry+2, 2)
if not 0 < field_type < len(FIELD_TYPES): if not 0 < field_type < len(FIELD_TYPES):
# unknown field type # unknown field type
raise ValueError, \ raise ValueError('unknown type %d in tag 0x%04X' % (field_type, tag))
'unknown type %d in tag 0x%04X' % (field_type, tag)
typelen=FIELD_TYPES[field_type][0] typelen=FIELD_TYPES[field_type][0]
count=self.s2n(entry+4, 4) count=self.s2n(entry+4, 4)
offset=entry+8 offset=entry+8
@ -807,8 +806,8 @@ class EXIF_header:
values, field_offset, values, field_offset,
count*typelen) count*typelen)
if self.debug: if self.debug:
print ' %s: %s' % (tag_name, print(' %s: %s' % (tag_name,
repr(self.tags[ifd_name+' '+tag_name])) repr(self.tags[ifd_name+' '+tag_name])))
# extract uncompressed TIFF thumbnail (like pulling teeth) # extract uncompressed TIFF thumbnail (like pulling teeth)
# we take advantage of the pre-existing layout in the thumbnail IFD as # we take advantage of the pre-existing layout in the thumbnail IFD as
@ -920,7 +919,7 @@ class EXIF_header:
for i in (('MakerNote Tag 0x0001', MAKERNOTE_CANON_TAG_0x001), for i in (('MakerNote Tag 0x0001', MAKERNOTE_CANON_TAG_0x001),
('MakerNote Tag 0x0004', MAKERNOTE_CANON_TAG_0x004)): ('MakerNote Tag 0x0004', MAKERNOTE_CANON_TAG_0x004)):
if self.debug: if self.debug:
print ' SubMakerNote BitSet for ' +i[0] print(' SubMakerNote BitSet for ' +i[0])
self.canon_decode_tag(self.tags[i[0]].values, i[1]) self.canon_decode_tag(self.tags[i[0]].values, i[1])
return return
@ -937,7 +936,7 @@ class EXIF_header:
else: else:
val=value[i] val=value[i]
if self.debug: if self.debug:
print ' '+name+':', val print(' '+name+':', val)
self.tags['MakerNote '+name]=val self.tags['MakerNote '+name]=val
# process an image file (expects an open file object) # process an image file (expects an open file object)
@ -973,7 +972,7 @@ def process_file(file, debug=0, noclose=0):
# deal with the EXIF info we found # deal with the EXIF info we found
if debug: if debug:
print {'I': 'Intel', 'M': 'Motorola'}[endian], 'format' print({'I': 'Intel', 'M': 'Motorola'}[endian], 'format')
hdr=EXIF_header(file, endian, offset, debug) hdr=EXIF_header(file, endian, offset, debug)
ifd_list=hdr.list_IFDs() ifd_list=hdr.list_IFDs()
ctr=0 ctr=0
@ -986,7 +985,7 @@ def process_file(file, debug=0, noclose=0):
else: else:
IFD_name='IFD %d' % ctr IFD_name='IFD %d' % ctr
if debug: if debug:
print ' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i) print(' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i))
hdr.tags['Exif Offset'] = offset hdr.tags['Exif Offset'] = offset
hdr.tags['Exif Endian'] = endian hdr.tags['Exif Endian'] = endian
hdr.tags[IFD_name+' IFDOffset'] = i hdr.tags[IFD_name+' IFDOffset'] = i
@ -995,28 +994,28 @@ def process_file(file, debug=0, noclose=0):
exif_off=hdr.tags.get(IFD_name+' ExifOffset') exif_off=hdr.tags.get(IFD_name+' ExifOffset')
if exif_off: if exif_off:
if debug: if debug:
print ' EXIF SubIFD at offset %d:' % exif_off.values[0] print(' EXIF SubIFD at offset %d:' % exif_off.values[0])
hdr.dump_IFD(exif_off.values[0], 'EXIF') hdr.dump_IFD(exif_off.values[0], 'EXIF')
# Interoperability IFD contained in EXIF IFD # Interoperability IFD contained in EXIF IFD
#intr_off=hdr.tags.get('EXIF SubIFD InteroperabilityOffset') #intr_off=hdr.tags.get('EXIF SubIFD InteroperabilityOffset')
intr_off=hdr.tags.get('EXIF InteroperabilityOffset') intr_off=hdr.tags.get('EXIF InteroperabilityOffset')
if intr_off: if intr_off:
if debug: if debug:
print ' EXIF Interoperability SubSubIFD at offset %d:' \ print(' EXIF Interoperability SubSubIFD at offset %d:' \
% intr_off.values[0] % intr_off.values[0])
hdr.dump_IFD(intr_off.values[0], 'EXIF Interoperability', hdr.dump_IFD(intr_off.values[0], 'EXIF Interoperability',
dict=INTR_TAGS) dict=INTR_TAGS)
# deal with MakerNote contained in EXIF IFD # deal with MakerNote contained in EXIF IFD
if hdr.tags.has_key('EXIF MakerNote'): if 'EXIF MakerNote' in hdr.tags:
if debug: if debug:
print ' EXIF MakerNote SubSubIFD at offset %d:' \ print(' EXIF MakerNote SubSubIFD at offset %d:' \
% intr_off.values[0] % intr_off.values[0])
hdr.decode_maker_note() hdr.decode_maker_note()
# GPS IFD # GPS IFD
gps_off=hdr.tags.get(IFD_name+' GPSInfoOffset') gps_off=hdr.tags.get(IFD_name+' GPSInfoOffset')
if gps_off: if gps_off:
if debug: if debug:
print ' GPS SubIFD at offset %d:' % gps_off.values[0] print(' GPS SubIFD at offset %d:' % gps_off.values[0])
hdr.dump_IFD(gps_off.values[0], 'GPS', dict=GPS_TAGS) hdr.dump_IFD(gps_off.values[0], 'GPS', dict=GPS_TAGS)
ctr+=1 ctr+=1
@ -1035,7 +1034,7 @@ def process_file(file, debug=0, noclose=0):
# Sometimes in a TIFF file, a JPEG thumbnail is hidden in the MakerNote # Sometimes in a TIFF file, a JPEG thumbnail is hidden in the MakerNote
# since it's not allowed in a uncompressed TIFF IFD # since it's not allowed in a uncompressed TIFF IFD
if not hdr.tags.has_key('JPEGThumbnail'): if 'JPEGThumbnail' not in hdr.tags:
thumb_off=hdr.tags.get('MakerNote JPEGThumbnail') thumb_off=hdr.tags.get('MakerNote JPEGThumbnail')
if thumb_off: if thumb_off:
file.seek(offset+thumb_off.values[0]) file.seek(offset+thumb_off.values[0])
@ -1050,21 +1049,21 @@ if __name__ == '__main__':
import sys import sys
if len(sys.argv) < 2: if len(sys.argv) < 2:
print 'Usage: %s files...\n' % sys.argv[0] print('Usage: %s files...\n' % sys.argv[0])
sys.exit(0) sys.exit(0)
for filename in sys.argv[1:]: for filename in sys.argv[1:]:
try: try:
file=open(filename, 'rb') file=open(filename, 'rb')
except: except:
print filename, 'unreadable' print(filename, 'unreadable')
print print()
continue continue
print filename+':' print(filename+':')
# data=process_file(file, 1) # with debug info # data=process_file(file, 1) # with debug info
data=process_file(file, 1) data=process_file(file, 1)
if not data: if not data:
print 'No EXIF information found' print('No EXIF information found')
continue continue
# x=data.keys() # x=data.keys()

@ -13,42 +13,42 @@ def compose(delta, old):
def deg2o(d): def deg2o(d):
map={90:6, 270:8, 180:3} map={90:6, 270:8, 180:3}
if map.has_key(d): if d in map:
return map[d] return map[d]
else: else:
return 0 return 0
if len(sys.argv) < 2: if len(sys.argv) < 2:
print 'Usage: %s [[+]orientnum] file\n' % sys.argv[0] print('Usage: %s [[+]orientnum] file\n' % sys.argv[0])
sys.exit(1) sys.exit(1)
try: try:
if len(sys.argv) == 2: if len(sys.argv) == 2:
filename=sys.argv[1] filename=sys.argv[1]
file=open(filename, "r"); file=open(filename, 'rb');
else: else:
filename=sys.argv[2] filename=sys.argv[2]
mod=sys.argv[1] mod=sys.argv[1]
fd = os.open(filename, os.O_RDWR) fd = os.open(filename, os.O_RDWR)
file=os.fdopen(fd,'r') file=os.fdopen(fd,'rb')
# check file exists and is readable # check file exists and is readable
file.read(1) file.read(1)
file.seek(0,0) file.seek(0,0)
except: except:
print 'Cannot open', filename print('Cannot open', filename)
sys.exit(1) sys.exit(1)
tags=exif.process_file(file,0,1) tags=exif.process_file(file,0,1)
if not tags: if not tags:
print 'no EXIF information in', filename print('no EXIF information in', filename)
sys.exit(1) sys.exit(1)
if not tags.has_key('Exif Offset') \ if 'Exif Offset' not in tags \
or not tags.has_key('Image Qt::Orientation'): or 'Image Orientation' not in tags:
print 'cannot get orientation info in', filename print('cannot get orientation info in', filename)
sys.exit(1) sys.exit(1)
exifp = tags['Exif Offset'] exifp = tags['Exif Offset']
endian = tags['Exif Endian'] endian = tags['Exif Endian']
tagp = tags['Image Qt::Orientation'].field_offset tagp = tags['Image Orientation'].field_offset
orientp = exifp + tagp orientp = exifp + tagp
@ -59,11 +59,11 @@ file.seek(orientp)
o = ord(file.read(1)) o = ord(file.read(1))
if o < 1 or o > 8: if o < 1 or o > 8:
print 'orientation out of range', o print('orientation out of range', o)
sys.exit(1) sys.exit(1)
if len(sys.argv) == 2: if len(sys.argv) == 2:
print 'orientation is', o print('orientation is', o)
sys.exit(0) sys.exit(0)
try: try:
@ -74,18 +74,18 @@ try:
elif deg2o(deltao) != 0: elif deg2o(deltao) != 0:
newo = compose(deg2o(deltao), o) newo = compose(deg2o(deltao), o)
else: else:
print 'cannot understand orientation modification', mod print('cannot understand orientation modification', mod)
sys.exit(1) # it will still hit the except ... how to fix? sys.exit(1) # it will still hit the except ... how to fix?
else: else:
newo = int(mod) newo = int(mod)
except: except:
print 'expected numeric orientation and got',mod print('expected numeric orientation and got',mod)
sys.exit(1) sys.exit(1)
if newo < 1 or newo > 8: if newo < 1 or newo > 8:
newo = deg2o(newo) newo = deg2o(newo)
if newo == 0: if newo == 0:
print 'cannot understand orientation', deltao print('cannot understand orientation', deltao)
sys.exit(1) sys.exit(1)
os.lseek(fd,orientp,0) os.lseek(fd,orientp,0)
@ -93,12 +93,12 @@ os.write(fd,chr(newo))
# Thumbnail orientation : # Thumbnail orientation :
thumb_ifdp = 0 thumb_ifdp = 0
if tags.has_key('Thumbnail Qt::Orientation'): if 'Thumbnail Orientation' in tags:
thumb_tagp = tags['Thumbnail Qt::Orientation'].field_offset thumb_tagp = tags['Thumbnail Orientation'].field_offset
thumb_orientp = exifp + thumb_tagp thumb_orientp = exifp + thumb_tagp
if endian == 'M': # MM byte order if endian == 'M': # MM byte order
thumb_orientp += 1 thumb_orientp += 1
os.lseek(fd,thumb_orientp,0) os.lseek(fd,thumb_orientp,0)
os.write(fd,chr(newo)) os.write(fd,chr(newo))
print 'orientation changed from', o, 'to', newo print('orientation changed from', o, 'to', newo)

Loading…
Cancel
Save