Guest User

Untitled

a guest
Feb 15th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. from argparse import ArgumentTypeError
  4. from pathlib import Path
  5.  
  6. from cement.core import backend, foundation, controller, handler
  7.  
  8. from . import logic
  9.  
  10.  
  11. def directory(path):
  12. p = Path(path)
  13. if p.is_dir():
  14. return p
  15. ArgumentTypeError('Path "%s" is not a directory' % path)
  16.  
  17.  
  18. ARG_UID = (['--uid', '-u'], dict(action='store', type=str, help='profile uid'))
  19. ARG_DIR = (['--dir', '-d'], dict(action='store', type=directory,
  20. help='Directory to export to'))
  21.  
  22.  
  23. class BaseController(controller.CementBaseController):
  24. class Meta:
  25. label = 'base'
  26.  
  27. @controller.expose(help='Show current granted permissions')
  28. def permissions(self):
  29. logic.show_perms()
  30.  
  31.  
  32. class LoginController(controller.CementBaseController):
  33. class Meta:
  34. label = 'login'
  35. stacked_on = 'base'
  36. stacked_type = 'nested'
  37. description = ('Request and store authentication token'
  38. ' for given username and password')
  39. arguments = [
  40. (['username'], dict(action='store', type=str)),
  41. (['password'], dict(action='store', type=str)),
  42. ]
  43.  
  44. @controller.expose(hide=True)
  45. def default(self):
  46. logic.login(username=self.app.pargs.username,
  47. password=self.app.pargs.password)
  48.  
  49.  
  50. class ProfileController(controller.CementBaseController):
  51. class Meta:
  52. label = 'profile'
  53. stacked_on = 'base'
  54. stacked_type = 'nested'
  55. description = 'Manipulate basic profile information'
  56. config_defaults = {'uid': None}
  57. arguments = [
  58. ARG_UID,
  59. ]
  60.  
  61. @controller.expose()
  62. def list(self):
  63. logic.list_users()
  64.  
  65. @controller.expose()
  66. def save(self):
  67. logic.save_profile(self.app.pargs.uid)
  68.  
  69. @controller.expose()
  70. def show(self):
  71. logic.get_user(self.app.pargs.uid)
  72.  
  73.  
  74. class FrieldsController(controller.CementBaseController):
  75. class Meta:
  76. label = 'friends'
  77. stacked_on = 'base'
  78. stacked_type = 'nested'
  79. description = 'Manipulate friends'
  80. arguments = [
  81. ARG_UID,
  82. (['--sleep', '-s'], dict(action='store', type=float, default=.5,
  83. help='delay between requests'))
  84. ]
  85.  
  86. @controller.expose(help='Save friends of a user')
  87. def save(self):
  88. # raise NotImplementedError()
  89. logic.save_friends(self.app.pargs.uid, self.app.pargs.sleep)
  90.  
  91. @controller.expose(help='Show friends of a user')
  92. def show(self):
  93. logic.show_friends(self.app.pargs.uid)
  94.  
  95.  
  96. class PhotoController(controller.CementBaseController):
  97. class Meta:
  98. label = 'photos'
  99. stacked_on = 'base'
  100. stacked_type = 'nested'
  101. description = 'manipulate photos and albums'
  102. arguments = [
  103. ARG_UID,
  104. ARG_DIR,
  105. ]
  106.  
  107. @controller.expose(help='Save photos of a user')
  108. def save(self):
  109. logic.save_photos(self.app.pargs.uid)
  110.  
  111. @controller.expose(help='Export photos of a user to dir')
  112. def export(self):
  113. logic.export_photos(self.app.pargs.uid, self.app.pargs.dir)
  114.  
  115.  
  116. class VideoController(controller.CementBaseController):
  117. class Meta:
  118. label = 'videos'
  119. stacked_on = 'base'
  120. stacked_type = 'nested'
  121. description = 'manipulate videos'
  122. arguments = [
  123. ARG_UID,
  124. ]
  125.  
  126. @controller.expose(help='Save videos of a user')
  127. def save(self):
  128. logic.save_videos(self.app.pargs.uid)
  129.  
  130. @controller.expose(help='Show links to videos of a user')
  131. def list(self):
  132. logic.list_videos(self.app.pargs.uid)
  133.  
  134.  
  135. # class DocsController(controller.CementBaseController):
  136. # class Meta:
  137. # label = 'docs'
  138. # stacked_on = 'base'
  139. # stacked_type = 'nested'
  140. # description = 'manipulate docs'
  141. # arguments = [
  142. # ARG_UID,
  143. # ]
  144.  
  145. # @controller.expose(help='Save docs of a user')
  146. # def save(self):
  147. # logic.save_docs(self.app.pargs.uid)
  148.  
  149. # @controller.expose(help='Show links to docs of a user')
  150. # def list(self):
  151. # logic.list_docs(self.app.pargs.uid)
  152.  
  153.  
  154. class NotesController(controller.CementBaseController):
  155. class Meta:
  156. label = 'notes'
  157. stacked_on = 'base'
  158. stacked_type = 'nested'
  159. description = 'manipulate notes'
  160. arguments = [
  161. ARG_UID,
  162. ]
  163.  
  164. @controller.expose(help='Save notes of a user')
  165. def save(self):
  166. logic.save_notes(self.app.pargs.uid)
  167.  
  168. @controller.expose(help='Show notes of a user')
  169. def list(self):
  170. logic.list_notes(self.app.pargs.uid)
  171.  
  172.  
  173. class WallController(controller.CementBaseController):
  174. class Meta:
  175. label = 'wall'
  176. stacked_on = 'base'
  177. stacked_type = 'nested'
  178. description = 'manipulate wall'
  179. arguments = [
  180. ARG_UID,
  181. ]
  182.  
  183. @controller.expose(help='Save wall of a user')
  184. def save(self):
  185. logic.save_wall(self.app.pargs.uid)
  186.  
  187.  
  188. class MessagesController(controller.CementBaseController):
  189. class Meta:
  190. label = 'messages'
  191. stacked_on = 'base'
  192. stacked_type = 'nested'
  193. description = 'manipulate messages'
  194.  
  195. @controller.expose(help='Save messages of a user')
  196. def save(self):
  197. logic.save_messages()
  198.  
  199.  
  200. class FavesController(controller.CementBaseController):
  201. class Meta:
  202. label = 'faves'
  203. stacked_on = 'base'
  204. stacked_type = 'nested'
  205. description = 'manipulate faves'
  206.  
  207. @controller.expose(help='Save faves of a user')
  208. def save(self):
  209. logic.save_faves()
  210.  
  211.  
  212. class EverythingController(controller.CementBaseController):
  213. class Meta:
  214. label = 'everything'
  215. stacked_on = 'base'
  216. stacked_type = 'nested'
  217. description = 'manipulate everything'
  218. arguments = [
  219. ARG_UID,
  220. ]
  221.  
  222. @controller.expose(help='Save everything of a user')
  223. def save(self):
  224. logic.save_everything(self.app.pargs.uid)
  225.  
  226.  
  227. class VKDumpApp(foundation.CementApp):
  228. class Meta:
  229. label = 'vkdump'
  230. handlers = [
  231. BaseController,
  232. LoginController,
  233. ProfileController,
  234. FrieldsController,
  235. PhotoController,
  236. VideoController,
  237. # DocsController,
  238. NotesController,
  239. WallController,
  240. MessagesController,
  241. FavesController,
  242. EverythingController,
  243. ]
Add Comment
Please, Sign In to add comment