ohld / igbot

🐙 Free scripts, bots and Python API wrapper. Get free followers with our auto like, auto follow and other scripts!
https://hikerapi.com/p/N2P6iqiM
Apache License 2.0
4.71k stars 1.47k forks source link

How to send emoji in the comments on windows? #835

Closed EightShift closed 5 years ago

EightShift commented 5 years ago

Before submitting an issue, make sure you have:

Purpose of your issue?

How to send emoji in the comments on windows? I want to use the ultimate schedule. When I worked on Linux, everything was fine. But now I would like to transfer everything to Windows. I suffered for a long time with encodings and I still didn’t work ...

All I got was an error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 2: character maps to

Or instead of comments, there was something like this: РєРЅРє яю;C; лул лул

I'm already tortured ... nothing happens. If this is not possible, then you will have to return to Linux.

ohld commented 5 years ago

are you using python 3?

EightShift commented 5 years ago

@ohld Yes.

arlidge commented 5 years ago

I am not on Windows, I use macOS Mojave ...I just copied the Emoji from https://getemoji.com/ and pasted it straight into the ultimate schedule comments I wanted the bot to comment with. Have you tried this?

EightShift commented 5 years ago

@ohld @arlidge, No. I have not tried. But I have no doubt that it will work, as well as on Linux. I'm just wondering if this is possible on windows. The fact is that when I send Emoji via Instabot to Direct (on Windows), Emoji looks fine. But when i comment, they looks like strange signs. To send in direct, made this:

#!/usr/bin/env python3

from glob import glob
import os
import sys
import threading
import time
import datetime

from tqdm import tqdm

sys.path.append(os.path.join(sys.path[0], '../'))
import schedule
from instabot import Bot, utils

username = "super_mega_username"
password = "super_mega_password"
USERSLIST = "USERSLIST.txt"
MESSAGE = open("MESSAGE.txt", "r", encoding="utf8").read()
SENDED_USERSLIST = "SENDED_USERSLIST.txt"

bot = Bot()
bot.login(username=username, password=password)

wait = 1500 #Delay

for user in utils.file(USERSLIST).list:
    if user not in utils.file(SENDED_USERSLIST).list:
        try:
            current_time = datetime.datetime.now().strftime('%H:%M:%S')
            if bot.send_message(MESSAGE, user):
                print (current_time, " >>> Sent a message to user: " + user)
                open(SENDED_USERSLIST, "a").write(user + "\n")
                open("MESSAGE.txt", "r", encoding="utf8").close()
                time.sleep(wait)
            else:
                print (current_time, " >>> Can't send message to user: " + user)
        except:
            pass
arlidge commented 5 years ago

@EightShift - I think because you are encoding with utf8. I think emojis have two utf8 encodings... I have not seen that in any of the scripts that comment. In the .txt file for my comments I just paste the emoji directly and it works, all in python3.

EightShift commented 5 years ago

@arlidge i know. my script for sending emojies in direct - works correctly. But, when i try to send a comment with emojies using ultimate method, i dont get wanted result. Maybe instabot have another method to send comments?

When i using linux, i using emojies in txt like you. And i want to get this on windows, but cant :(

@ohld

arlidge commented 5 years ago

Im not too sure then mate, I thought it would be the same because it's python. Keep hunting, hopefully someone can help you soon. Sorry I am of no help.

EightShift commented 5 years ago

@ohld, @arlidge I GOT IT! in utils.py i added encoding="utf8":

    @property
    def list(self):
        with open(self.fname, 'r', encoding="utf8") as f:
            lines = [x.strip('\n') for x in f.readlines()]
            return [x for x in lines if x]

and emojis looks fine!!! but i have an error in console, and i added .encode("utf-8") in bot_comment.py:

def comment_medias(self, medias):
    broken_items = []
    self.logger.info("Going to comment %d medias." % (len(medias)))
    for media in tqdm(medias):
        if not self.is_commented(media):
            text = self.get_comment()
            self.logger.info("Commented with text: %s" % text.encode("utf-8"))
            if not self.comment(media, text):
                self.delay('comment')
                broken_items = medias[medias.index(media):]
                break
    self.logger.info("DONE: Total commented on %d medias. " %
                     self.total['comments'])
    return broken_items

...and goodbye error :)

arlidge commented 5 years ago

Woohoo :) stoked you got it figured out! Now onto automation. 💯

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.