Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetched images filename bug #11

Closed
shwoop opened this issue Mar 4, 2014 · 1 comment
Closed

Fetched images filename bug #11

shwoop opened this issue Mar 4, 2014 · 1 comment
Labels

Comments

@shwoop
Copy link
Owner

shwoop commented Mar 4, 2014

database.py has a bug where

localfilename = hashlib.md5(origfile).hexdigest() + ext[0]

should be

localfilename = hashlib.md5(origfile).hexdigest() + ext

so all locally stored files have been given extension of "."

470 files have the issue.

shwoop added a commit that referenced this issue Mar 4, 2014
@shwoop shwoop added the bug label Mar 4, 2014
@shwoop
Copy link
Owner Author

shwoop commented Mar 4, 2014

The bad files were corrected via:

  1 import sqlite3, subprocess
  2 
  3 dbpath = 'db/laamaj.db'
  4 imgdir = 'db/img/'
  5 
  6 con = sqlite3.connect(dbpath)
  7 cur = con.cursor()
  8 
  9 op = cur.execute("select ws_id, ws_url, ws_localfile from websites where ws_localfile like '%.' order by ws_id desc")
 10 op = [x for x in op]
 11 #op = cur.execute("select ws_id, ws_url, ws_localfile from websites where ws_id = '9455'")
 12 
 13 for key, url, lfile in op:
 14     print key, url, lfile
 15     extension = url.split(u'.')[-1]
 16     newfile = u'%s%s' % (lfile, extension)
 17     cmd = u'mv %s%s %s%s' % (imgdir, lfile, imgdir,  newfile)
 18     retcode = subprocess.call(cmd, shell=True)
 19     if retcode == 0:
 20         script = "update websites set ws_localfile = '%s' where ws_id = '%s'" % (newfile, key)
 21         print script
 22         cur.execute(script)
 23         con.commit()
 24     else:
 25         print 'failed to move'

@shwoop shwoop closed this as completed Mar 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant