Ramzes228

text_browser

Mar 15th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1.  
  2. nytimes_com = '''
  3. This New Liquid Is Magnetic, and Mesmerizing
  4.  
  5. Scientists have created “soft” magnets that can flow
  6. and change shape, and that could be a boon to medicine
  7. and robotics. (Source: New York Times)
  8.  
  9.  
  10. Most Wikipedia Profiles Are of Men. This Scientist Is Changing That.
  11.  
  12. Jessica Wade has added nearly 700 Wikipedia biographies for
  13. important female and minority scientists in less than two
  14. years.
  15.  
  16. '''
  17.  
  18. bloomberg_com = '''
  19. The Space Race: From Apollo 11 to Elon Musk
  20.  
  21. It's 50 years since the world was gripped by historic images
  22. of Apollo 11, and Neil Armstrong -- the first man to walk
  23. on the moon. It was the height of the Cold War, and the charts
  24. were filled with David Bowie's Space Oddity, and Creedence's
  25. Bad Moon Rising. The world is a very different place than
  26. it was 5 decades ago. But how has the space race changed since
  27. the summer of '69? (Source: Bloomberg)
  28.  
  29.  
  30. Twitter CEO Jack Dorsey Gives Talk at Apple Headquarters
  31.  
  32. Twitter and Square Chief Executive Officer Jack Dorsey
  33. addressed Apple Inc. employees at the iPhone maker’s headquarters
  34. Tuesday, a signal of the strong ties between the Silicon Valley giants.
  35. '''
  36.  
  37. # write your code here
  38.  
  39. import os
  40.  
  41. while True:
  42.     address = input()
  43.     if address == "exit":
  44.         break
  45.     elif "." not in address:
  46.         print("Error: Incorrect URL")
  47.         continue
  48.     elif address == "exit":
  49.         break
  50.     elif address == "bloomberg.com":
  51.         content = bloomberg_com
  52.  
  53.     elif address == "nytimes.com":
  54.         content = nytimes_com
  55.     print(content)
  56.  
  57.     directory = input()
  58.     try:
  59.         os.mkdir(directory)
  60.         print("Directory  ", directory, "  Created")
  61.     except FileExistsError:
  62.         print("Directory  ", directory, "already exists")
  63.  
  64.  
  65.     file_name = address[:address.rfind('.')]
  66.     print("имя файла  " + file_name)
  67.  
  68.     fh = open(directory + r"/" + file_name, "a")
  69.     fh.write(content)
  70.     fh.close()
  71.     print("сохранили в файл   " + directory + r"/" + file_name)
  72.     try:
  73.         open_file = input()
  74.         handle = open(directory + r"/" + open_file, "r")
  75.         data = handle.read()
  76.         print(data)
  77.         handle.close()
  78.     except FileNotFoundError:
  79.         print("Error, no file")
Advertisement
Add Comment
Please, Sign In to add comment