216 lines
7.1 KiB
Python
Executable File
216 lines
7.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
import reddit_imgs.sync
|
|
import reddit_imgs.fetch
|
|
import reddit_imgs.fetch2
|
|
import reddit_imgs.reorganize
|
|
import reddit_imgs.wallpapers
|
|
import reddit_imgs.thumbnailize
|
|
import reddit_imgs.hashit
|
|
import reddit_imgs.hashit2
|
|
import reddit_imgs.normalizetobmp
|
|
import reddit_imgs.cachedhash
|
|
import reddit_imgs.download_pruner
|
|
import reddit_imgs.suggest_subreddits_from_links
|
|
import reddit_imgs.condensate_hashes
|
|
|
|
import os
|
|
import sys
|
|
import shutil
|
|
wdir = os.path.abspath('.')
|
|
|
|
|
|
def ensureFolderAvailability():
|
|
if not os.path.exists(os.path.join(wdir, 'w')):
|
|
os.makedirs(os.path.join(wdir, 'w'))
|
|
if not os.path.exists(os.path.join(wdir, 'd')):
|
|
os.makedirs(os.path.join(wdir, 'd'))
|
|
if not os.path.exists(os.path.join(wdir, 'i')):
|
|
os.makedirs(os.path.join(wdir, 'i'))
|
|
if not os.path.exists(os.path.join(wdir, 'r')):
|
|
os.makedirs(os.path.join(wdir, 'r'))
|
|
|
|
|
|
def managesubreddits():
|
|
i = ''
|
|
while i != '0':
|
|
print('\n'*100)
|
|
print('----------------------------------------------')
|
|
print(' Subreddit Manager ')
|
|
print('----------------------------------------------')
|
|
print('1) List monitored subreddits')
|
|
print('2) Add monitored subreddit')
|
|
print('3) Remove monitored subreddit')
|
|
print('4) Set as wallpaper source')
|
|
print('5) Unset as wallpaper source')
|
|
print()
|
|
print('0) Back')
|
|
print('----------------------------------------------')
|
|
print()
|
|
print('Enter your choice:')
|
|
i = input()
|
|
i = i.strip()
|
|
print()
|
|
print()
|
|
subreddits_dir = os.path.join(wdir, 'r')
|
|
def subreddits_isfolder(sr): return os.path.isdir(
|
|
os.path.join(subreddits_dir, sr))
|
|
subreddits = sorted(
|
|
filter(subreddits_isfolder, os.listdir(subreddits_dir)))
|
|
if i in ['1', '3', '4', '5']:
|
|
print('Subreddits monitored:')
|
|
for sr in subreddits:
|
|
print('/r/{0}'.format(sr), end='')
|
|
if os.path.isfile(os.path.join(subreddits_dir, sr, 'wallpaper.flag')):
|
|
print('\t\t(wallpaper)')
|
|
else:
|
|
print()
|
|
print()
|
|
if i == '1':
|
|
print('Press enter to continue')
|
|
input()
|
|
if i == '3':
|
|
print('Enter the subreddit you want to get rid of:')
|
|
rem = input('/r/')
|
|
try:
|
|
shutil.rmtree(os.path.join(subreddits_dir, rem))
|
|
except:
|
|
pass
|
|
print()
|
|
print('Done.')
|
|
print('Press enter to continue')
|
|
input()
|
|
elif i == '2':
|
|
print('Enter the subreddit you want to add:')
|
|
add = input('/r/')
|
|
try:
|
|
os.makedirs(os.path.join(subreddits_dir, add))
|
|
except:
|
|
pass
|
|
print()
|
|
print('Done.')
|
|
print('Press enter to continue')
|
|
input()
|
|
elif i == '4':
|
|
print('Enter the subreddit you want to set as wallpaper source:')
|
|
add = input('/r/')
|
|
try:
|
|
dd = os.path.join(subreddits_dir, add)
|
|
if not os.path.exists(dd):
|
|
os.makedirs(dd)
|
|
f = open(os.path.join(dd, 'wallpaper.flag'), 'w')
|
|
f.write('')
|
|
f.close()
|
|
except:
|
|
pass
|
|
print()
|
|
print('Done.')
|
|
print('Press enter to continue')
|
|
input()
|
|
elif i == '5':
|
|
print('Enter the subreddit you want to unset as wallpaper source:')
|
|
add = input('/r/')
|
|
try:
|
|
dd = os.path.join(subreddits_dir, add)
|
|
if not os.path.exists(dd):
|
|
os.makedirs(dd)
|
|
f = open(os.path.join(dd, 'wallpaper.flag'), 'w')
|
|
f.write('')
|
|
f.close()
|
|
os.remove(os.path.join(dd, 'wallpaper.flag'))
|
|
except:
|
|
pass
|
|
print()
|
|
print('Done.')
|
|
print('Press enter to continue')
|
|
input()
|
|
|
|
|
|
def mainmenu():
|
|
i = ''
|
|
while i != '0':
|
|
print('\n'*100)
|
|
print('----------------------------------------------')
|
|
print(' Reddit Image Downloader ')
|
|
print('----------------------------------------------')
|
|
print('1) Manage subreddits')
|
|
print('2) Get link list to be downloaded from reddit')
|
|
print('3) Download grabbed links')
|
|
print('4) Organize by hashes')
|
|
print('5) Generate thumbnails')
|
|
print('6) Group and put nice names on downloaded data')
|
|
print('7) Sepparate wallpapers')
|
|
print()
|
|
print('0) Quit')
|
|
print('----------------------------------------------')
|
|
print()
|
|
print('Enter your choice:')
|
|
i = input()
|
|
i = i.strip()
|
|
if i == '1':
|
|
managesubreddits()
|
|
elif i == '2':
|
|
reddit_imgs.sync.main()
|
|
elif i == '3':
|
|
reddit_imgs.fetch.main()
|
|
elif i == '4':
|
|
reddit_imgs.hashit.main()
|
|
elif i == '5':
|
|
reddit_imgs.thumbnailize.main()
|
|
elif i == '6':
|
|
reddit_imgs.reorganize.main()
|
|
elif i == '7':
|
|
reddit_imgs.wallpapers.main()
|
|
|
|
|
|
def main():
|
|
# ensureFolderAvailability()
|
|
if len(sys.argv) > 1:
|
|
cmdline()
|
|
else:
|
|
mainmenu()
|
|
|
|
|
|
def cmdline():
|
|
cmds = sys.argv[1:]
|
|
available_commands = ((
|
|
('sync', reddit_imgs.sync.cmdline),
|
|
('fetch', reddit_imgs.fetch2.cmdline),
|
|
('suggest_subreddits_from_links', reddit_imgs.suggest_subreddits_from_links.cmdline),
|
|
('prune_downloads', reddit_imgs.download_pruner.cmdline),
|
|
('hashit', reddit_imgs.hashit2.cmdline),
|
|
('condensate_hashes', reddit_imgs.condensate_hashes.cmdline),
|
|
# ('cachedhash', reddit_imgs.cachedhash.main),
|
|
# ('hashit', reddit_imgs.hashit.main),
|
|
# ('normalizetobmp', reddit_imgs.normalizetobmp.main),
|
|
# ('thumbnailize', reddit_imgs.thumbnailize.main),
|
|
# ('reorganize', reddit_imgs.reorganize.main),
|
|
# ('wallpapers', reddit_imgs.wallpapers.main),
|
|
))
|
|
available_commands_names = tuple(
|
|
list(map(lambda a: a[0], available_commands)))
|
|
for cmd in cmds:
|
|
if cmd.split(':', 1)[0] not in available_commands_names:
|
|
print('Usage {0} [{1}]'.format(sys.argv[0],
|
|
'/'.join(available_commands_names)))
|
|
return
|
|
for cmd in cmds:
|
|
command_ran = False
|
|
for acmd in available_commands:
|
|
if cmd.split(':', 1)[0] == acmd[0]:
|
|
x = cmd.split(':', 1)
|
|
command_ran = True
|
|
fcmd = acmd[1]
|
|
if len(x) == 1:
|
|
fcmd()
|
|
else:
|
|
fcmd(encoded_args=x[1])
|
|
if not command_ran:
|
|
print('Usage {0} [{1}]'.format(sys.argv[0],
|
|
'/'.join(available_commands_names)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|