Originally posted by Kafka
I just finished rearranging my bookcase. My assignment for the Python microcredential is due today and I can't do it without cheating, so I'm wondering if it's even worth it when I can do the PCAP.
use my code!
from bs4 import BeautifulSoup
html = '<div class="skyblock-event" title="Spooky" id="skyblock-event_Spooky"><i class="fa fa-flask"></i><br /><strong>Spooky</strong><p class="skyblock-event-text" id="skyblock-event-text_Spooky">1 day</p></div>'
soup = BeautifulSoup(html, 'html.parser')
text = soup.find('p', class_='skyblock-event-text').text
my_text = soup.find("p", class_="skyblock-event-text").text
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.text = tk.Text(self)
self.text.pack()
self.update_button = tk.Button(self, text="CHECK HOW LONG UNTIL SPOOKY", command=self.update_text)
self.update_button.pack()
def update_text(self):
# Your code to pull text from the webpage and display it
# Here's an example:
self.text.insert("end", my_text+ "\n")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
import datetime
import time
from tkinter import *
# Create the tkinter window
window = Tk()
window.title("Spooky Clock")
# Define the functions
def update_time():
# Get the current time
now = datetime.datetime.now()
# Update the time label
time_label.config(text=now.strftime("%H:%M:%S"))
# Schedule the function to run again after 1 second
window.after(1000, update_time)
def set_alarm():
# Get the alarm time
alarm_time = f"{alarm_hour.get():02d}:{alarm_minute.get():02d}"
# Display the alarm time
alarm_label.config(text=f"Alarm set for {alarm_time}")
# Schedule the alarm to go off
while True:
now = datetime.datetime.now()
current_time = now.strftime("%H:%M")
if current_time == alarm_time:
alarm_window = Toplevel()
alarm_window.title("Alarm!")
alarm_label = Label(alarm_window, text="Wake up!")
alarm_label.pack()
break
time.sleep(1)
# Create the widgets
time_label = Label(window, font=("Arial", 80))
alarm_label = Label(window, font=("Arial", 20), fg="red")
hour_label = Label(window, text="Hour:")
alarm_hour = Spinbox(window, from_=0, to=23)
minute_label = Label(window, text="Minute:")
alarm_minute = Spinbox(window, from_=0, to=59)
set_alarm_button = Button(window, text="Set Alarm", command=set_alarm)
# Pack the widgets
time_label.pack()
alarm_label.pack()
hour_label.pack()
alarm_hour.pack()
minute_label.pack()
alarm_minute.pack()
set_alarm_button.pack()
# Start the clock
update_time()
# Run the tkinter event loop
window.mainloop()
COMMANDS = [
{
"command":"dice",
"description":"Dice game. Usage: /dice (bet value)"
},
{
"command":"balance",
"description":"Shows your current balance and deposit address."
},
{
"command":"withdraw",
"description":"Withdraws your money. Usage: /withdraw (litecoin address)"
},
]
from requests import Session
import json
from time import sleep
from time import time as unix_timestamp
import numpy as np
import sqlite3
from .Constants import _DBFILE, _ADMINS
self.username = None
self.last_name = json_object["last_name"]
self.last_name = None
self.is_bot = bool(json_object["is_bot"])
self.language_code = "en"
self.user_id = json_object["id"]
# Session initialization and assignment of API URL
self.s = Session()
self.s.headers["User-Agent"] = "TeleBot"
self.api_key = api_key
self.base_url = "https://api.telegram.org/bot"+self.api_key
self.proxy = {
"socks5":"socks5h://localhost:9050",
"http":"socks5h://localhost:9050",
"https":"socks5h://localhost:9050"
}
# Use API URL to get bot username and bot ID
me = self.getMe()["result"]
self.bot_id = int(me["id"])
self.bot_name = me["username"]
print("Telegram bot initialized - "+self.bot_name+", UID "+str(self.bot_id))
r = self.s.post(self.base_url+"/sendMessage", json=post_data, proxies=self.proxy)
j = json.loads(r.text)
r = self.s.post(self.base_url+"/sendAnimation", json=post_data, proxies=self.proxy)
j = json.loads(r.text)
r = self.s.post(self.base_url+"/editMessageText", json=post_data, proxies=self.proxy)
j = json.loads(r.text)
# Gets updates and returns a list of other Telegram-related objects from the json body of the response
j = json.loads(r.text)
#return j
ret = []
tgu.save()
ret.append(tgu)
raise ValueError("'ok' field wasn't True. Here's a full dump of the response:\n"+json.dumps(j, indent=4))
# update is a Update object with type=="message"
# If the update object isn't correct, this will return False
# If the update object is valid and correct, this will reply to the given message
chat_id = update.data["chat"]["id"]
import itertools
def read_words_from_file(file_name):
with open(file_name, "r") as file:
return file.read().splitlines()
def get_combinations(words_list, num_words):
return itertools.combinations(words_list, num_words)
def main():
file_names = ["list1.txt", "list2.txt", "list3.txt"]
num_words_per_list = [2, 3, 1]
words_lists = [read_words_from_file(file_name) for file_name in file_names]
for words_list, num_words in zip(words_lists, num_words_per_list):
combinations = get_combinations(words_list, num_words)
for combination in combinations:
print(" ".join(combination))
if __name__ == "__main__":
main()
import subprocess
import win32api
def F12_handler(event):
if event.KeyID == 123:
subprocess.Popen("mspaint.exe")
win32api.SetWindowsHookEx(win32con.WH_KEYBOARD_LL, F12_handler)
win32api.PumpMessages()
import random
""" ASCII art for a dice
dice_art = [
" ____ ",
" /\' .\'\\ ",
"/: \\___\\ ",
"\\' / . / ",
" \\/___/ ",
" \\'__'\\/"
⚀⚁⚂⚃⚄⚅
My lucky dice
⚀ ⚁ ⚂ ⚃ ⚄ ⚅
]"""
# types of dice
d20 = range(1, 21)
d6 = range(1, 7)
# function to roll a dice
def roll_dice(d6):
result = random.randint(1, dice_type) # Generate a random number between 1 and the specified dice type
return result
#return random.randint(1, 6)
# function to display dice result
def display_result(result):
print(f"The dice rolled {result}!")
# example usage
dice_type = 6 # This can be changed to any other dice type (e.g. 4, 8, 10, 12, 20, etc.)
dice_result = roll_dice(dice_type)
display_result(dice_result)
##Note that this code is incomplete and there are a few TODOs that need to be implemented. The display_result function needs to be fleshed out to actually display the result on the screen using Tkinter, and the function for randomly picking something from a list with a toggle button needs to be added. Additionally, this code does not create a graphical interface or user input functionality, so you would need to add that as well to create a fully functional dice rolling program.##