Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use Pytmi Async? #1

Closed
nickzsche opened this issue Mar 6, 2022 · 1 comment
Closed

How can I use Pytmi Async? #1

nickzsche opened this issue Mar 6, 2022 · 1 comment

Comments

@nickzsche
Copy link

I can use the twitch api directly, but not in Pyqt5. What should I do? I couldn't find the answer for hours. What should I do, where should I write? I can't run it in the interface. It works without interface. It does nothing with the interface. How can I run it? Thank you.

This is how it's work:

`import asyncio
import pytmi

listToken = ["Token List"]
listNick = ["User List"]
channel = "**************************"
messagesList = ["Hello","Hi","Goodnight"]
for i in range(0,3):

async def main() -> None:
    # nick = input("Insert your Twitch nickname: ").lstrip()
    # token = input("Insert your Twitch OAuth token: ").lstrip()
    # channel = input("Insert the channel to join: ").lstrip()

    client = pytmi.TmiClient()
    await client.login_oauth(listToken[i], listNick[i])

    await client.join(channel)
    await client.send_privmsg(messagesList[i])

    await client.part(channel)
    await client.logout()


if __name__ == "__main__":
    try:
        loop = asyncio.new_event_loop()
        loop.run_until_complete(main())
    except:
        print("Something went wrong.")`

Not running:

`def YorumAttirCalistir(self):

    os.chdir("Data")
    os.chdir("Kullanıcılar")
    listToken = []
    listNick = []
   
    dosyaOuath = open("Oauth.txt", "r", encoding="UTF8")
    for i in dosyaOuath:
        i = i[:-1]
        listToken.append(i)
        newListToken = listToken
    dosyaNick = open("Oauth.txt", "r", encoding="UTF8")
    for i in dosyaNick:
        i = i[:-1]
        listNick.append(i)
        newListNick = listNick
    os.chdir("..")
    os.chdir("..")
    os.chdir("Data")
    os.chdir("Chat")
    os.chdir("Valorant Chat")
    messagesList = []
    dosyaComment = open("Valorant.txt", "r", encoding="UTF8")
    for i in dosyaComment:
        i = i[:-1]
        messagesList.append(i)
        newListMessages = messagesList   
    channel = "shawncutstheh"
    token = newListToken
    nick = newListNick
    yorum = newListMessages
    def YorumAttir():
        for i in range(0,4):
            async def main() -> None:
                    # nick = input("Insert your Twitch nickname: ").lstrip()
                    # token = input("Insert your Twitch OAuth token: ").lstrip()
                    # channel = input("Insert the channel to join: ").lstrip()

                client = pytmi.TmiClients()
                await client.login_oauth(token[i], nick[i])

                await client.join(channel)
                await client.send_privmsg(yorum[i])

                await client.part(channel)
                await client.logout()


                if __name__ == "__main__":
                    try:
                        loop = QEventLoop.new_event_loop()
                        loop.run_until_complete(main())
                    except:
                        print("Something went wrong.")
    YorumAttirThread = threading.Thread(
        target=YorumAttir)
   YorumAttirThread.start()`
@bynect
Copy link
Owner

bynect commented Mar 6, 2022

Hello, I am not an expert of Qt, but maybe you could try something like this.

I removed the threading part so you should not use run_until_complete if the function needs not to block

def YorumAttirCalistir(self):

    os.chdir("Data")
    os.chdir("Kullanıcılar")
    listToken = []
    listNick = []

    dosyaOuath = open("Oauth.txt", "r", encoding="UTF8")
    for i in dosyaOuath:
        i = i[:-1]
        listToken.append(i)
        newListToken = listToken
    dosyaNick = open("Oauth.txt", "r", encoding="UTF8")
    for i in dosyaNick:
        i = i[:-1]
        listNick.append(i)
        newListNick = listNick
    os.chdir("..")
    os.chdir("..")
    os.chdir("Data")
    os.chdir("Chat")
    os.chdir("Valorant Chat")
    messagesList = []
    dosyaComment = open("Valorant.txt", "r", encoding="UTF8")
    for i in dosyaComment:
        i = i[:-1]
        messagesList.append(i)
        newListMessages = messagesList
    channel = "shawncutstheh"
    token = newListToken
    nick = newListNick
    yorum = newListMessages
    async def YorumAttir():
        client = pytmi.TmiClient()
        for i in range(0,4):
            await client.login_oauth(token[i], nick[i])

            await client.join(channel)
            await client.send_privmsg(yorum[i])

            await client.part(channel)
            await client.logout()
    try:
        loop = QEventLoop.new_event_loop()
        loop.run_until_complete(YorumAttir())
    except:
        print("Something went wrong.")

@bynect bynect closed this as completed Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants