def getProductLink(self): webhook = DiscordWebhooks("enter discord webhook") response = self.s.get(self.link) responseSoup = BeautifulSoup(response.text, "lxml") productSelect = responseSoup.find("select", {"name": "id"}) sizes = productSelect.findAll("option") productTitle = responseSoup.find("h1", {"class", "product-single__title"}) img = responseSoup.find("img") imgURL = "http:" + img['src'] webhookContent = "" for size in sizes: if "value" and not "disabled" in str(size): inStockSize = size.text.strip() variant = size["value"] print(inStockSize + " (" + variant + ")") webhookContent += f"{inStockSize} ([{variant}](http://www.kith.com/cart/{variant}:1))\n" webhook.set_content(title=productTitle.text.strip(), description=(webhookContent), url=self.link, color=0xdc00ff) webhook.set_footer( text="oapi webhook", icon_url= 'https://avatars1.githubusercontent.com/u/58406347?s=460&v=4') webhook.set_thumbnail(url=imgURL) webhook.send()
def job(): url = 'add-your-webhook-url-here' apiurl = 'add-your-api-url-here' res = requests.get(apiurl) data = res.json() # current weather data extract ctemp = data['current']['temp'] cwspeed = data['current']['wind_speed'] ccloud = data['current']['clouds'] cwmain = data['current']['weather'][0]['main'] cwdesc = data['current']['weather'][0]['description'] cicon = data['current']['weather'][0]['icon'] #int to string and some calculations c_temp = str(ctemp) c_clouds = str(ccloud) c_wspeed = str(cwspeed) #h_temp = str(htemp) #h_clouds = str(hcloud) # message design for current weather cweather = DiscordWebhooks(url) cweather.set_content(title="Current Weather") cweather.set_thumbnail(url='http://openweathermap.org/img/wn/' + cicon + '@4x.png') cweather.add_field(name='Temperature :', value=str(c_temp + " ºC")) cweather.add_field(name='Wind speed :', value=str(c_wspeed + " km/h")) cweather.add_field(name=(cwmain + ' :'), value=cwdesc) cweather.add_field(name='Cloudiness :', value=(c_clouds + '%')) cweather.set_footer(text='Source - OpenWeather') cweather.send()
def test_set_thumbnail(self): """ Tests the set_thumbnail method and ensures the data gets added to the payload. """ webhook = DiscordWebhooks('webhook_url') webhook.set_content(content='Montezuma') webhook.set_thumbnail( url='https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') expected_payload = \ { 'content': 'Montezuma', 'embeds': [ { 'fields': [], 'image': {}, 'author': {}, 'thumbnail': { 'url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'footer': {}, } ] } self.assertEquals(webhook.format_payload(), expected_payload)
def test_complex_embed(self): """ Tests a combination of all methods to form a complex payload object. """ webhook = DiscordWebhooks('webhook_url') webhook.set_content(content='Montezuma', title='Best Cat Ever', description='Seriously', \ url='http://github.com/JamesIves', color=0xF58CBA, timestamp='2018-11-09T04:10:42.039Z') webhook.set_image( url='https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.set_thumbnail( url='https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.set_author( name='James Ives', url='https://jamesiv.es', icon_url= 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.set_footer( text='Footer', icon_url= 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.add_field(name='Field', value='Value!') self.maxDiff = None expected_payload = \ { 'content': 'Montezuma', 'embeds': [ { 'title': 'Best Cat Ever', 'description': 'Seriously', 'url': 'http://github.com/JamesIves', 'color': 16092346, 'timestamp': '2018-11-09T04:10:42.039Z', 'fields': [ { 'name': 'Field', 'value': 'Value!', 'inline': False } ], 'image': { 'url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'author': { 'name': 'James Ives', 'url': 'https://jamesiv.es', 'icon_url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'thumbnail': { 'url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'footer': { 'text': 'Footer', 'icon_url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, } ] } self.assertEquals(webhook.format_payload(), expected_payload)
def job(): url = 'add-your-webhook-url-here' newsapi = NewsApiClient(api_key='add-your-api-key-here') data = newsapi.get_top_headlines(language='en',country='in') if data['status'] == 'ok': ar1t = data['articles'][0]['title'] ar1d = data['articles'][0]['url'] ar1i = data['articles'][0]['urlToImage'] ar2t = data['articles'][1]['title'] ar2d = data['articles'][1]['url'] ar2i = data['articles'][1]['urlToImage'] ar3t = data['articles'][2]['title'] ar3d = data['articles'][2]['url'] ar3i = data['articles'][2]['urlToImage'] ar4t = data['articles'][3]['title'] ar4d = data['articles'][3]['url'] ar4i = data['articles'][3]['urlToImage'] ar5t = data['articles'][4]['title'] ar5d = data['articles'][4]['url'] ar5i = data['articles'][4]['urlToImage'] cnews1 = DiscordWebhooks(url) cnews1.set_author(name="Today's top headlines") cnews1.set_content(title=ar1t,url=ar1d) cnews1.set_thumbnail(url=ar1i) cnews2 = DiscordWebhooks(url) cnews2.set_content(title=ar2t,url=ar2d) cnews2.set_thumbnail(url=ar2i) cnews3 = DiscordWebhooks(url) cnews3.set_content(title=ar3t,url=ar3d) cnews3.set_thumbnail(url=ar3i) cnews4 = DiscordWebhooks(url) cnews4.set_content(title=ar4t,url=ar4d) cnews4.set_thumbnail(url=ar4i) cnews5 = DiscordWebhooks(url) cnews5.set_content(title=ar5t,url=ar5d) cnews5.set_thumbnail(url=ar5i) cnews5.set_footer(text='Source - newsapi.org') cnews1.send() cnews2.send() cnews3.send() cnews4.send() cnews5.send() else: cnews = DiscordWebhooks(url) cnews.set_content(title="Sorry, we will be back soon with live news!") cnews.send()
def score(): webhook = DiscordWebhooks(web_hook_url) r = requests.get("https://api.sigmadraconis.games/scores") servers = r.json()["scores"] s = set([s["Server"] for s in servers]) print(s) for s in s: ss = [x for x in servers if x["Server"] == s] print(ss) p = set([s["PlanetId"] for s in ss]) print(p) d = "" webhook.set_content(content="\n", title=f"Scores for {s}") for p in p: sss = [x for x in ss if x["PlanetId"] == p] d += f"\n**Planet**: ***{p}***\n" for sss in sss: d += f"\n**Faction**: {sss['FactionName']}\n" d += f"**Score**: {sss['Points']}\n" print(d) webhook.set_content(content="", title=f"Scores for **{s}**", url="https://sigmadraconis.games/koth.html", description=d, timestamp=str(datetime.datetime.now()), color=0xF58CBA) webhook.set_author( name="KOTH", icon_url= "https://cdn.discordapp.com/attachments/657771421564534807/689958406194200666/draconis_logo.png", url="https://sigmadraconis.games/koth.html") webhook.set_footer( text="https://sigmadraconis.games/koth.html", icon_url= "https://cdn.discordapp.com/attachments/657771421564534807/689958406194200666/draconis_logo.png" ) webhook.set_thumbnail( url= "https://cdn.discordapp.com/attachments/657771421564534807/689958406194200666/draconis_logo.png" ) webhook.send() time.sleep(5)