Guest User

Untitled

a guest
May 8th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mport urllib
  2. import requests
  3. import json
  4. from wordpress_xmlrpc import Client, WordPressPost
  5. from wordpress_xmlrpc.methods import posts
  6. from wordpress_xmlrpc.compat import xmlrpc_client
  7. from wordpress_xmlrpc.methods import media, posts
  8. import os
  9. import time
  10. class Custom_WP_XMLRPC:
  11. def post_article(self, wpUrl, wpUserName, wpPassword, articleTitle, articleCategories, articleContent, articleTags,
  12. PhotoUrl):
  13. self.path = os.getcwd() + "\\00000001.jpg"
  14. self.articlePhotoUrl = PhotoUrl
  15. self.wpUrl = wpUrl
  16. self.wpUserName = wpUserName
  17. self.wpPassword = wpPassword
  18. # Download File
  19. f = open(self.path, 'wb')
  20. f.write(urllib.urlopen(self.articlePhotoUrl).read())
  21. f.close()
  22. # Upload to WordPress
  23. client = Client(self.wpUrl, self.wpUserName, self.wpPassword)
  24. filename = self.path
  25. # prepare metadata
  26. data = {'name': 'picture.jpg', 'type': 'image/jpg', }
  27.  
  28. # read the binary file and let the XMLRPC library encode it into base64
  29. with open(filename, 'rb') as img:
  30. data['bits'] = xmlrpc_client.Binary(img.read())
  31. response = client.call(media.UploadFile(data))
  32. attachment_id = response['id']
  33. # Post
  34. post = WordPressPost()
  35. post.title = articleTitle
  36. post.content = articleContent
  37. post.terms_names = {'post_tag': articleTags, 'category': articleCategories}
  38. post.post_status = 'publish'
  39. post.thumbnail = attachment_id
  40. post.id = client.call(posts.NewPost(post))
  41. print
  42. 'Post Successfully posted. Its Id is: ', post.id
  43.  
  44. for i in range(328, 7762):
  45. r =requests.get("https://yts.am/api/v2/movie_details.json?movie_id="+str(i))
  46. b = r.json()
  47. genres = b["data"]["movie"]["genres"]
  48. hash = b["data"]["movie"]["torrents"][0]["hash"]
  49. image = b["data"]["movie"]["large_cover_image"]
  50. movie_year = b["data"]["movie"]["year"]
  51. movie_name = b["data"]["movie"]["title"]
  52. movie_url = b["data"]["movie"]["url"]
  53. screenshoot = movie_name.replace(" ", "_")
  54. screenshoot1 = (
  55. 'https://yts.am/assets/images/movies/' + screenshoot + '_' + str(movie_year) + '/large-screenshot2.jpg')
  56. screenshoot2 = (
  57. 'https://yts.am/assets/images/movies/' + screenshoot + '_' + str(movie_year) + '/large-screenshot3.jpg')
  58. dheeraj1 = requests.get(
  59. 'https://trendingimages.in/api/1/upload/?key=10db24f4d3d9eff6eb89f2b008a87ea1&source=' + screenshoot1 + '&format=txt')
  60. dheeraj2 = requests.get(
  61. 'https://trendingimages.in/api/1/upload/?key=10db24f4d3d9eff6eb89f2b008a87ea1&source=' + screenshoot2 + '&format=txt')
  62. image1 = dheeraj1.text
  63. image2 = dheeraj2.text
  64. ariclePhotoUrl='https://trendingimages.in/images/2018/05/04/746844905c43f734b2a9b1eb8333b2c9.png'
  65. wpUrl='http://techbangla.co.in/xmlrpc.php'
  66. wpUserName='urusername'
  67. wpPassword='password'
  68. #Post Title
  69. articleTitle=movie_name
  70. #Post Body/Description
  71. articleContent='<p style="text-align: center;"><img class="alignnone size-medium" src="'+image+'" width="1280" height="720" /></p>' \
  72. '<center>[mks_button size="large" title="Magnet Download" style="squared" url="http://techbangla.co.in/u/index.html#magnet:?xt=urn:btih:'+hash+'&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969" target="_self" bg_color="#1e73be" txt_color="#FFFFFF" icon="fa-magnet" icon_type="fa" nofollow="0"]</center>' \
  73. '<h2 style="text-align: center;">SCREENSHOOTS</h2>' \
  74. '<code><img src="'+image1+'" border="0" />' \
  75. '<img src="'+image2+'" border="0" /></code>'
  76. #list of tags
  77. articleTags=genres
  78. #list of Categories
  79. articleCategories=['English Movies']
  80.  
  81. #########################################
  82. # Creating Class object & calling the xml rpc custom post Function
  83. #########################################
  84. xmlrpc_object = Custom_WP_XMLRPC()
  85. #On Post submission this function will print the post id
  86. xmlrpc_object.post_article(wpUrl,wpUserName,wpPassword,articleTitle, articleCategories, articleContent, articleTags,ariclePhotoUrl)
  87. print("test")
Add Comment
Please, Sign In to add comment