Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mport urllib
- import requests
- import json
- from wordpress_xmlrpc import Client, WordPressPost
- from wordpress_xmlrpc.methods import posts
- from wordpress_xmlrpc.compat import xmlrpc_client
- from wordpress_xmlrpc.methods import media, posts
- import os
- import time
- class Custom_WP_XMLRPC:
- def post_article(self, wpUrl, wpUserName, wpPassword, articleTitle, articleCategories, articleContent, articleTags,
- PhotoUrl):
- self.path = os.getcwd() + "\\00000001.jpg"
- self.articlePhotoUrl = PhotoUrl
- self.wpUrl = wpUrl
- self.wpUserName = wpUserName
- self.wpPassword = wpPassword
- # Download File
- f = open(self.path, 'wb')
- f.write(urllib.urlopen(self.articlePhotoUrl).read())
- f.close()
- # Upload to WordPress
- client = Client(self.wpUrl, self.wpUserName, self.wpPassword)
- filename = self.path
- # prepare metadata
- data = {'name': 'picture.jpg', 'type': 'image/jpg', }
- # read the binary file and let the XMLRPC library encode it into base64
- with open(filename, 'rb') as img:
- data['bits'] = xmlrpc_client.Binary(img.read())
- response = client.call(media.UploadFile(data))
- attachment_id = response['id']
- # Post
- post = WordPressPost()
- post.title = articleTitle
- post.content = articleContent
- post.terms_names = {'post_tag': articleTags, 'category': articleCategories}
- post.post_status = 'publish'
- post.thumbnail = attachment_id
- post.id = client.call(posts.NewPost(post))
- print
- 'Post Successfully posted. Its Id is: ', post.id
- for i in range(328, 7762):
- r =requests.get("https://yts.am/api/v2/movie_details.json?movie_id="+str(i))
- b = r.json()
- genres = b["data"]["movie"]["genres"]
- hash = b["data"]["movie"]["torrents"][0]["hash"]
- image = b["data"]["movie"]["large_cover_image"]
- movie_year = b["data"]["movie"]["year"]
- movie_name = b["data"]["movie"]["title"]
- movie_url = b["data"]["movie"]["url"]
- screenshoot = movie_name.replace(" ", "_")
- screenshoot1 = (
- 'https://yts.am/assets/images/movies/' + screenshoot + '_' + str(movie_year) + '/large-screenshot2.jpg')
- screenshoot2 = (
- 'https://yts.am/assets/images/movies/' + screenshoot + '_' + str(movie_year) + '/large-screenshot3.jpg')
- dheeraj1 = requests.get(
- 'https://trendingimages.in/api/1/upload/?key=10db24f4d3d9eff6eb89f2b008a87ea1&source=' + screenshoot1 + '&format=txt')
- dheeraj2 = requests.get(
- 'https://trendingimages.in/api/1/upload/?key=10db24f4d3d9eff6eb89f2b008a87ea1&source=' + screenshoot2 + '&format=txt')
- image1 = dheeraj1.text
- image2 = dheeraj2.text
- ariclePhotoUrl='https://trendingimages.in/images/2018/05/04/746844905c43f734b2a9b1eb8333b2c9.png'
- wpUrl='http://techbangla.co.in/xmlrpc.php'
- wpUserName='urusername'
- wpPassword='password'
- #Post Title
- articleTitle=movie_name
- #Post Body/Description
- articleContent='<p style="text-align: center;"><img class="alignnone size-medium" src="'+image+'" width="1280" height="720" /></p>' \
- '<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>' \
- '<h2 style="text-align: center;">SCREENSHOOTS</h2>' \
- '<code><img src="'+image1+'" border="0" />' \
- '<img src="'+image2+'" border="0" /></code>'
- #list of tags
- articleTags=genres
- #list of Categories
- articleCategories=['English Movies']
- #########################################
- # Creating Class object & calling the xml rpc custom post Function
- #########################################
- xmlrpc_object = Custom_WP_XMLRPC()
- #On Post submission this function will print the post id
- xmlrpc_object.post_article(wpUrl,wpUserName,wpPassword,articleTitle, articleCategories, articleContent, articleTags,ariclePhotoUrl)
- print("test")
Add Comment
Please, Sign In to add comment