Skip to content

Instantly share code, notes, and snippets.

@theand
Created May 10, 2014 10:28
Show Gist options
  • Save theand/cdbec1c173dd0e53f746 to your computer and use it in GitHub Desktop.
Save theand/cdbec1c173dd0e53f746 to your computer and use it in GitHub Desktop.
get jpg file list and make link html
#!/home/bin/python
import os
import os.path
def getJpgList(aDir):
list = os.listdir(aDir)
jpg_list = []
for each in list:
if each.count('.') == 2:
continue
if each.find('.jpg') == -1:
continue
jpg_list.append(each)
return jpg_list
def makeJpgListFile(aDir, aList):
file = open( os.path.join('../download_picture/'+aDir+'.html'), "w")
for each in aList:
link = '<a href="%s">%s</a>' % ( os.path.join('http://the-host-url.net/albums/',aDir, each), each)
file.write(link+'\n')
file.close()
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print 'insufficient argument'
if sys.argv[1][-1] == '/':
print 'omit the /'
sys.exit(0)
if os.path.isdir(sys.argv[1]) !=1 :
print 'directory doesn\'t exist'
sys.exit(0)
list = getJpgList(sys.argv[1])
makeJpgListFile(sys.argv[1], list)
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment