Guest User

Untitled

a guest
Jul 27th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import sqlite3
  2. import os
  3. import argparse
  4.  
  5. con=sqlite3.connect('opensubs.db')
  6. con.row_factory = sqlite3.Row
  7.  
  8. def save(name, file, path):
  9.     name=name.split('"')[1]
  10.     with open('{}/{}'.format(path, name), 'wb' ) as w:
  11.         w.write(file)
  12.  
  13. def get_range(start,end):
  14.     with con:
  15.         cur = con.cursor()
  16.         cur.execute("select * from subz where num >= (?) and num <= (?)",  (start,end,))
  17.         rows = cur.fetchall()
  18.     return rows
  19.  
  20. def get_single(num):
  21.     with con:
  22.         cur = con.cursor()
  23.         cur.execute("select * from subz where num = (?)",  (num,))
  24.         row = cur.fetchone()
  25.     return row
  26.  
  27. ##save all
  28. ##tmp_start=9200000
  29. ##while tmp_start >=0:
  30. ##    rows = get_range(tmp_start-1000, tmp_start)
  31. ##    tmp_start-=1000
  32. ##    for row in rows:
  33. ##        save(row['name'], row['file'])
  34.  
  35. #examples
  36. ##ten = get_range (0, 10)
  37. ##one = get_single(1    )
  38. ##print(one['name'])
  39. ##print('-')
  40. ##for row in ten:
  41. ##    print(row['name'])
  42. ####    save(row['name'], row['file'])
  43.  
  44. if __name__ == "__main__":
  45.     parser = argparse.ArgumentParser()
  46.     parser.add_argument('-s','--start', help='extract start'                    , required=True)
  47.     parser.add_argument('-e','--end'  , help='extract end (omit to extract one)', required=False)
  48.     parser.add_argument('-p','--path' , help='path'                             , required=False)
  49.     args = vars(parser.parse_args())
  50.     path = args.get('path') if args.get('path') else './tmp'
  51.    
  52.     if not os.path.isdir(path):
  53.         os.mkdir(path)
  54.     if args.get('end'):
  55.         rows = get_range(args.get('start'), args.get('end'))
  56.         for row in rows:
  57.             save(row['name'], row['file'], path)
  58.     else:
  59.         row = get_single(args.get('start'))
  60.         save(row['name'], row['file'], path)
  61.  
Advertisement
Add Comment
Please, Sign In to add comment