Fix extension parsing

This commit is contained in:
Robohash 2022-11-04 14:10:00 -04:00
parent e04794dd87
commit 2a3fc56a09
4 changed files with 18 additions and 16 deletions

View File

@ -16,6 +16,9 @@ class Robohash(object):
Takes in the string to make a Robohash out of. Takes in the string to make a Robohash out of.
""" """
# Default to png
self.format = 'png'
# Optionally remove an images extension before hashing. # Optionally remove an images extension before hashing.
if ignoreext is True: if ignoreext is True:
string = self._remove_exts(string) string = self._remove_exts(string)
@ -41,7 +44,6 @@ class Robohash(object):
# Get the colors in set1 # Get the colors in set1
self.colors = self._listdirs(self.resourcedir + 'sets/set1') self.colors = self._listdirs(self.resourcedir + 'sets/set1')
self.format = 'png'
def _remove_exts(self,string): def _remove_exts(self,string):
""" """
@ -93,7 +95,7 @@ class Robohash(object):
directories = [] directories = []
for root, dirs, files in natsort.natsorted(os.walk(path, topdown=False)): for root, dirs, files in natsort.natsorted(os.walk(path, topdown=False)):
for name in dirs: for name in dirs:
if name[:1] is not '.': if name[:1] != '.':
directories.append(os.path.join(root, name)) directories.append(os.path.join(root, name))
directories = natsort.natsorted(directories) directories = natsort.natsorted(directories)
@ -117,7 +119,6 @@ class Robohash(object):
Build our Robot! Build our Robot!
Returns the robot image itself. Returns the robot image itself.
""" """
# Allow users to manually specify a robot 'set' that they like. # Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all # Ensure that this is one of the allowed choices, or allow all
# If they don't set one, take the first entry from sets above. # If they don't set one, take the first entry from sets above.

View File

@ -1,2 +1,11 @@
User-agent: SpiritRover
Allow: Finally-coming-home
User-agent: T-1000
Allow: Liquid-metal-form
User-agent: WALL-E
Allow: Rebuilding-with-EVE
User-agent: * User-agent: *
Allow: / Allow: /

View File

@ -27,7 +27,6 @@ robo@robohash.org
<script src="//robohash.org/static/js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="//robohash.org/static/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="//robohash.org/static/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script> <script src="//robohash.org/static/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
<script src="//robohash.org/static/js/twitter.js" type="text/javascript" charset="utf-8"></script>
<script src="//robohash.org/static/js/tipsy.js" type="text/javascript" charset="utf-8"></script> <script src="//robohash.org/static/js/tipsy.js" type="text/javascript" charset="utf-8"></script>
@ -430,7 +429,7 @@ function submitform()
<span class="benefit_header">Styles of Robot</span> <span class="benefit_header">Styles of Robot</span>
<p>Want a JPG instead? Fine. PNG? Fine. Want it as a bitmap? I think you're nutty. But fine. Just change the <p>Want a JPG instead? Fine. PNG? Fine. Want it as a bitmap? I think you're nutty. But fine. Just change the
URL to request in any format you want. Use ?ignoreext=false to make the bots care about extensions.</p> URL to request in any format you want. If you want it to hash the whole thing, including the extension use ?ignoreext=false to ignore the extensions.</p>
</div><!-- end of benefit right --> </div><!-- end of benefit right -->
@ -606,10 +605,6 @@ Robohash.org" or something.
<!-- start of footer right --> <!-- start of footer right -->
<div id="footer_right"> <div id="footer_right">
<span class="follow"><a href="http://www.twitter.com/robohash" class="fade" title="Clicking on this will replace your cat with a robot.">Follow Us</a></span>
<div class="tweet"></div>
</div><!-- end of footer right --> </div><!-- end of footer right -->
</div><!-- end of footer container --> </div><!-- end of footer container -->

View File

@ -280,9 +280,7 @@ class ImgHandler(tornado.web.RequestHandler):
# Detect if the user has passed in a flag to ignore extensions. # Detect if the user has passed in a flag to ignore extensions.
# Pass this along to to Robohash obj later on. # Pass this along to to Robohash obj later on.
ignoreext = args.get('ignoreext','true').lower() == 'true'
ignoreext = args.get('ignoreext','false').lower() == 'true'
# Split the size variable in to sizex and sizey # Split the size variable in to sizex and sizey
if "size" in args: if "size" in args:
sizex,sizey = args.get('size').split("x") sizex,sizey = args.get('size').split("x")
@ -317,8 +315,7 @@ class ImgHandler(tornado.web.RequestHandler):
args['avatar'] = False args['avatar'] = False
# Create our Robohashing object # Create our Robohashing object
r = Robohash(string) r = Robohash(string=string,ignoreext=ignoreext)
# Allow users to manually specify a robot 'set' that they like. # Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all # Ensure that this is one of the allowed choices, or allow all
@ -364,11 +361,11 @@ class ImgHandler(tornado.web.RequestHandler):
bgset = args.get('bgset') bgset = args.get('bgset')
# We're going to be returning the image directly, so tell the browser to expect a binary. # We're going to be returning the image directly, so tell the browser to expect a binary.
self.set_header("Content-Type", "image/" + format) self.set_header("Content-Type", "image/" + r.format)
self.set_header("Cache-Control", "public,max-age=31536000") self.set_header("Cache-Control", "public,max-age=31536000")
# Build our Robot. # Build our Robot.
r.assemble(roboset=roboset,format=format,bgset=bgset,color=color,sizex=sizex,sizey=sizey) r.assemble(roboset=roboset,format=r.format,bgset=bgset,color=color,sizex=sizex,sizey=sizey)
# Print the Robot to the handler, as a file-like obj # Print the Robot to the handler, as a file-like obj
if r.format != 'datauri': if r.format != 'datauri':