class PinUploader: def __init__(self, cfg, logger): self.__cfg = cfg self.__pinterest = None self.__logger = logger self.__boards = None self.__create_obj() def __create_obj(self): self.__pinterest = Pinterest(email=self.__cfg['email'], password=self.__cfg['password'], username=self.__cfg['username'], cred_root=self.__cfg['cred_root'], user_agent=self.__cfg['user_agent']) self.__pinterest.login() self.__logger.info(f"{self.__cfg['username']} login") self.__boards = self.__pinterest.boards() def logout(self): self.__pinterest.logout() self.__logger.info(f"{self.__cfg['username']} logout") def __find_board_id(self, boardname): for board in self.__boards: if boardname == board['name']: return board['id'] def get_board_id(self, boardname): response = None board_id = self.__find_board_id(boardname) if board_id: return board_id response = self.__pinterest.create_board(name=boardname) if response is not None: board_id = response.json()['resource_response']['data']['id'] self.__logger.info("board {boardname} created") self.__boards.append({'name': boardname, 'id': board_id}) return board_id else: self.__logger.error("can't create board '{boardname}'") return None def create_pin(self, board_id, title, price, image_path, printbar_url): description = '''Принт выдерживает неограниченное количество стирок. Выберите тип ткани и вид печати. Продукция будет готова через 48 часов.''' hashtag = title.replace(' ', ' #') try: self.__pinterest.upload_pin( board_id=board_id, image_file=image_path, description=f"Цена: {price}. {description} {hashtag}", link=printbar_url, title=title) except requests.exceptions.HTTPError: self.__logger.error("can't create '{title}' pin") raise else: self.__logger.info("'{title}' pin created ")
api.update_with_media(temp, status=msg) os.remove(temp) # # Instagram bot = instabot.Bot() bot.login(username="******", password="******") temp = 'temp.jpg' request = requests.get(thumb, stream=True) with open(temp, 'wb') as image: for chunk in request: image.write(chunk) bot.upload_photo(temp, caption=msg) os.remove(temp + ".REMOVE_ME") # # Pinterest pinterest = Pinterest(email='*****@*****.**', password='******', username='******', cred_root='cred_dir') pinterest.login() pinterest.pin(board_id="802203821065010593", image_url=thumb, description=msg, title=title, link=current_post_url)
def getPinterestUserPinnedSubmissions(email, username, password, cacheFileName): submissions = [] lastIds = {} if not cacheFileName else loadPinterestCache(cacheFileName) updatedLastIds = lastIds pinterest = Pinterest(email=email, password=password, username=username, cred_root='pinterest_creds') logger.log("Logging in to Pinterest...") pinterest.login() boards = pinterest.boards(username=username) for board in boards: # Get all pins for the board board_pins = [] pin_batch = pinterest.board_feed(board_id=board['id']) while len(pin_batch) > 0: for pin in pin_batch: if pin['id'] not in lastIds: # Only using the dict for its key lookup updatedLastIds[pin['id']] = 1 board_pins.append(pin) pin_batch = pinterest.board_feed(board_id=board['id']) for pin in board_pins: # I'm not sure how important it is to support these if pin['type'] == 'story': continue newSubmission = Submission() newSubmission.source = u'Pinterest' # While pins do have titles, 90% of the time they seem useless newSubmission.title = pin['id'] # There is probably a way to figure out who the original pinner is, but oh well newSubmission.author = 'N/A' newSubmission.subreddit = board['url'] newSubmission.subredditTitle = board['name'] + '_Pinterest' if 'rich_summary' in pin and pin['rich_summary']: if 'display_description' in pin['rich_summary']: newSubmission.body = pin['rich_summary'][ 'display_description'] else: newSubmission.body = 'N/A' newSubmission.postUrl = pin['rich_summary']['url'] # What is actually downloaded newSubmission.bodyUrl = pin['images']['orig']['url'] submissions.append(newSubmission) if cacheFileName: savePinterestCache(cacheFileName, updatedLastIds) logger.log("Found {} new Pinterest submissions".format(len(submissions))) return submissions
def autoload(ch): global config global pinterest ch.add_command({ "trigger": ["!debug_prt"], "function": lambda message, client, args: get_boards(args[0]), "async": False, "admin": False, "hidden": True, "args_num": 1, "args_name": ["username"], "description": "Return a random image from the board specified", }) ch.add_command({ "trigger": ["!prt"], "function": pinterest_randomize_function, "async": True, "admin": False, "hidden": True, "args_num": 2, "args_name": ["username", "board"], "description": "Return a random image from the board specified", }) ch.add_command({ "trigger": ["!possum"], "function": lambda message, client, args: pinterest_randomize_function( message, client, ["jerryob1", "Opossums"]), "async": True, "admin": False, "hidden": False, "args_num": 0, "args_name": ["username", "board"], "description": "Return a random image from the board specified", }) # for guild in ch.guilds: # for ch.config.get(guild=guild, section="pinterest"): pinterest = Pinterest( email=ch.config.get(section="pinterest", key="email"), password=ch.config.get(section="pinterest", key="password"), username=ch.config.get(section="pinterest", key="username"), cred_root=ch.config.get(section="pinterest", key="tmpdir"), ) if datetime.datetime.now() == 8: pinterest.login()
from py3pin.Pinterest import Pinterest pinterest = Pinterest(email='*****@*****.**', password='******', username='******') print(pinterest.login()) def create_board_section(board_id='', section_name=''): return pinterest.create_board_section(board_id=board_id, section_name=section_name) board_id = '637400222200883506' for i in range(1996, 2021): date = str(i) create_board_section(board_id, date)