Guest User

Untitled

a guest
Dec 11th, 2019
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import argparse
  2. from scripts.conversion_news import read_news
  3. from scripts.conversion_news import unpack_json
  4. from scripts.conversion_news import unpack_news
  5. from scripts.conversion_news import unpack_with_date
  6. from scripts.create_xml import create_fb2
  7. from scripts.rss_parser import find_news
  8. from scripts.write_logs import write_log
  9. import os.path
  10.  
  11.  
  12. def parse_args():
  13. parser = argparse.ArgumentParser(description='Pure Python command-line RSS reader')
  14. parser.add_argument('source', help='RRS URL', nargs='?')
  15. parser.add_argument('--verbose', action='store_true', help='Outputs verbose status message')
  16. parser.add_argument('--version', action='version', version='%(prog)s 0.4', help='Print version info')
  17. parser.add_argument('--json', action='store_true', help='Print result as JSON in stdout')
  18. parser.add_argument('--limit', type=int, help='Limit topics if this parameter provided')
  19. parser.add_argument('--date', type=str, help='Print news by publication date')
  20. parser.add_argument('--output-path', dest='output_path', type=str, help='Path to save fb2')
  21. parser.add_argument('--to-fb2', dest='to_fb2', action='store_true', help='Conversion news in fb.2')
  22.  
  23. args = parser.parse_args()
  24.  
  25. return args
  26.  
  27.  
  28. def validate_args(args, news):
  29. if args.source == 'date':
  30. if args.date:
  31. len_standard_date = 8
  32. len_date = len(args.date)
  33. if len_date == len_standard_date:
  34. if args.to_fb2 and args.output_path:
  35. path = args.output_path.replace('\\', '\\\\')
  36. return os.path.exists(path)
  37. elif args.to_fb2:
  38. return True
  39. else:
  40. return True
  41. else:
  42. return False
  43. else:
  44. return False
  45. else:
  46. if args.json:
  47. if not args.date and \
  48. args.version and \
  49. args.verbose and \
  50. args.to_fb2 and \
  51. args.output_path:
  52. if args.limit:
  53. max_len = len(news)
  54. if max_len <= args.limit:
  55. return True
  56.  
  57. else:
  58. return False
  59. else:
  60. return True
  61. else:
  62. return False
  63. elif args.verbose:
  64. if not args.date and \
  65. args.version and \
  66. args.to_fb2 and \
  67. args.output_path and \
  68. args.limit and \
  69. args.json:
  70. return True
  71. else:
  72. return False
  73. elif args.limit:
  74. if not args.date and \
  75. args.version and \
  76. args.verbose and \
  77. args.to_fb2 and \
  78. args.output_path and \
  79. args.json:
  80. max_limit = len(news)
  81. if max_limit <= agrs.limit:
  82. return True
  83. else:
  84. return False
  85. elif args.to_fb2:
  86. if not args.date and \
  87. args.version and \
  88. args.verbose and \
  89. args.limit and \
  90. args.json:
  91. if args.output_path:
  92. return os.path.exists(args.output_path)
  93. else:
  94. return True
  95. else:
  96. return True
RAW Paste Data