Skip to content

Instantly share code, notes, and snippets.

@xjxckk
xjxckk / progress.py
Last active December 16, 2021 12:18
Telegram progress updater (Python)
import telegram
from time import sleep
bot = telegram.Bot(token='token')
msg = bot.send_message(chat_id='Channel ID', text='1/10')
# msg = bot.edit_message_text(text='2/10', chat_id='Channel ID', message_id=1) # To edit an old message
# print(msg.message_id)
for x in range(10):
progress = f'{x}/10'
@xjxckk
xjxckk / print_format.py
Last active December 16, 2021 12:18
Charmap print error (Python)
import sys
sys.stdout.reconfigure(encoding='utf-8')
@xjxckk
xjxckk / selenium.py
Last active December 16, 2021 12:17
Python selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
options = Options()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
@xjxckk
xjxckk / bs4.py
Last active December 16, 2021 12:17
Beautiful soup (Python)
from bs4 import BeautifulSoup
import requests
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
elements = soup.select('div.class')
element = soup.select_one('div#id')
print(element['href']) # Element link
print(element.text.strip()) # Element text
@xjxckk
xjxckk / variables.css
Last active December 16, 2021 12:20
CSS variables
:root {
--background: #202020;
--accent: #fff;
--tertiary: #191919;
--tertiary-accent: #313131;
}
@xjxckk
xjxckk / lookbehind.py
Last active December 16, 2021 12:19
Regex positive lookbehind to capture string after prefix (Python)
import regex
url = 'https://gfycat.com/HeftyHonoredHadrosaurus'
prefix = 'https://gfycat.com/'
# https://gfycat.com/HeftyHonoredHadrosaurus to HeftyHonoredHadrosaurus
slug = regex.search(rf'(?<={prefix})\w+', url).group()
@xjxckk
xjxckk / settings.py
Last active May 13, 2022 10:37
Python config parser
'''
settings.ini:
[Settings]
username = my_username
password = my_password
'''
from configparser import ConfigParser
@xjxckk
xjxckk / dates.py
Last active December 18, 2021 15:14
Python datetime, use strftime.org as a reference
from datetime import datetime
date = 'Sat Nov 13 11:54:30'
date = datetime.strptime(date, '%a %b %d %H:%M:%S') # Sat Nov 13 11:54:30
date = date.strftime("%Y-%m-%d, %H:%M:%S") # 2021-11-13, 11:54:30
@xjxckk
xjxckk / webhook.py
Last active June 17, 2024 06:30
Discord webhook with Python requests
import requests, json
url = 'https://discord.com/api/webhooks/123/131232123' # Create webhook in your server integrations and copy webhook URL here
## Text only:
data = {
"content" : "Test webhook message"
}
result = requests.post(url, json=data)
@xjxckk
xjxckk / jackett_download_all.js
Last active January 16, 2022 14:09
Download all search results in Jackett
let links = document.querySelectorAll('.downloadcolumn > .downloadlink:last-of-type') // Gets magnet link if available
for (const link of links){
window.location = link.href
}