微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果产品中有特定关键字,我如何使用此脚本将产品添加到购物篮?

如何解决如果产品中有特定关键字,我如何使用此脚本将产品添加到购物篮?

我想要实现的是使用下面的脚本将产品添加到购物篮中。

当在不和谐通知中检测到关键字时,下面的脚本会打开一个浏览器选项卡并将您带到产品页面,是否可以将该产品添加到购物车,同时使用其他脚本对其进行重定向

所以这里的关键字和网站是 https://www.cclonline.com/

open.py

import webbrowser
import asyncio
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import re

'''
by cleary#6546 // @preorderd
'''

#pylint: disable=anomalous-backslash-in-string

client = Bot('')
client.remove_command('help')

#prompt user enter keywords to check for in links
#keywords = list(map(str,input("Enter keywords seperated by space: ").split()))
keywords = ['cclonline.com',]

#prompt user to enter negative keywords that will prevent a browser window from opening to have no blacklisted words,press enter right away
blacklist = list(map(str,input("Enter blacklisted keywords seperated by space: ").split()))

#enter channel id(s) where links would be picked up (monitor channel id) seperated by commas. these should be ints
channels = ['000']
#enter token of discord account that has access to watch specified channels
token = 'tokenhere'

global start_count
start_count = 0

#check for keywords and blacklisted words in message urls and open browser if conditions are met
async def check_urls(urls):
    for url in urls:
        if any(x in url.lower() for x in keywords) and all(x not in url.lower() for x in blacklist):
            #enter path to chrome here,for windows 10,this should work
            webbrowser.get().open(url)
            print(f'Opened {url}')

@client.event
async def on_message(message):
    global start_count
    # temporary bypass to weird d.py cacheing issue
    # only print this info on the first time the client launches. this is due to d.py calling on_ready() after the bot regains connection
    if start_count == 0:
        print('\n{} is ready to cop some restocks.\n'.format(str(client.user)))
        if len(keywords) >= 1 and keywords[0] != '':
            print('Watching for keywords {}.\n'.format(','.join(keywords)))
        else:
            print('No keywords have been provided.\n')
        if len(blacklist) > 0:
            print('Ignoring keywords {}.\n'.format(','.join(blacklist)))
        else:
            print('No keywords currently blacklisted.\n')
        start_count += 1
    else:
        if message.channel.id in channels:
            if message.embeds:
                for embed in message.embeds:
                    toembed = embed.to_dict()
                    if str(toembed['type']).lower() != 'link':
                        try:
                            for field in toembed['fields']:
                                urls = re.findall("(?:(?:https?|ftp)://)?[\w/-?=%.#&+]+.[\w/-?=%.#&+]+",str(field))
                                if urls:
                                    await check_urls(urls)
                        except:
                            pass
            if message.content != '':
                urls = re.findall("(?:(?:https?|ftp)://)?[\w/-?=%.#&+]+.[\w/-?=%.#&+]+",message.content)
                if urls:
                    await check_urls(urls)

client.run(token,bot=False)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?