mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-16 14:52:11 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa00045dec | |||
| 06e3671ec2 | |||
| 0879796cc6 | |||
| 9f756b3092 | |||
| 579a3f2a52 | |||
| 5505022dbb | |||
| d2e5a34b87 | |||
| c7696fafdc | |||
| 7f3de2ea13 | |||
| ec505f050f | |||
| f55c4ce1a7 | |||
| 432abc73b9 | |||
| cdaf2589b3 |
@@ -6,3 +6,4 @@
|
|||||||
plugins
|
plugins
|
||||||
user_trunk.yaml
|
user_trunk.yaml
|
||||||
user.yaml
|
user.yaml
|
||||||
|
tmp
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[settings]
|
||||||
|
profile=black
|
||||||
@@ -2,9 +2,6 @@ rules:
|
|||||||
quoted-strings:
|
quoted-strings:
|
||||||
required: only-when-needed
|
required: only-when-needed
|
||||||
extra-allowed: ["{|}"]
|
extra-allowed: ["{|}"]
|
||||||
empty-values:
|
|
||||||
forbid-in-block-mappings: true
|
|
||||||
forbid-in-flow-mappings: true
|
|
||||||
key-duplicates: {}
|
key-duplicates: {}
|
||||||
octal-values:
|
octal-values:
|
||||||
forbid-implicit-octal: true
|
forbid-implicit-octal: true
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Generic, formatter-friendly config.
|
||||||
|
select = ["B", "D3", "E", "F"]
|
||||||
|
|
||||||
|
# Never enforce `E501` (line length violations). This should be handled by formatters.
|
||||||
|
ignore = ["E501"]
|
||||||
+23
-30
@@ -1,43 +1,36 @@
|
|||||||
|
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
|
||||||
|
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
|
||||||
version: 0.1
|
version: 0.1
|
||||||
cli:
|
cli:
|
||||||
version: 1.14.2
|
version: 1.20.1
|
||||||
|
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
|
||||||
plugins:
|
plugins:
|
||||||
sources:
|
sources:
|
||||||
- id: trunk
|
- id: trunk
|
||||||
ref: v1.2.1
|
ref: v1.4.5
|
||||||
uri: https://github.com/trunk-io/plugins
|
uri: https://github.com/trunk-io/plugins
|
||||||
lint:
|
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
|
||||||
enabled:
|
|
||||||
- checkov@2.4.9
|
|
||||||
- yamllint@1.32.0
|
|
||||||
- actionlint@1.6.25
|
|
||||||
- markdownlint@0.35.0
|
|
||||||
- trivy@0.44.1
|
|
||||||
- trufflehog@3.54.0
|
|
||||||
- pylint
|
|
||||||
- codespell
|
|
||||||
- cspell
|
|
||||||
- git-diff-check
|
|
||||||
- eslint
|
|
||||||
- prettier
|
|
||||||
- semgrep
|
|
||||||
- autopep8
|
|
||||||
- bandit
|
|
||||||
- black
|
|
||||||
- flake8
|
|
||||||
- isort
|
|
||||||
- mypy
|
|
||||||
- pylint
|
|
||||||
- ruff
|
|
||||||
- semgrep
|
|
||||||
- yapf
|
|
||||||
- gitleaks
|
|
||||||
|
|
||||||
runtimes:
|
runtimes:
|
||||||
enabled:
|
enabled:
|
||||||
- go@1.19.5
|
|
||||||
- node@18.12.1
|
- node@18.12.1
|
||||||
- python@3.10.8
|
- python@3.10.8
|
||||||
|
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
||||||
|
lint:
|
||||||
|
enabled:
|
||||||
|
- actionlint@1.6.27
|
||||||
|
- bandit@1.7.8
|
||||||
|
- black@24.3.0
|
||||||
|
- codespell
|
||||||
|
- checkov@3.2.48
|
||||||
|
- git-diff-check
|
||||||
|
- isort@5.13.2
|
||||||
|
- pylint
|
||||||
|
- markdownlint@0.39.0
|
||||||
|
- prettier@3.2.5
|
||||||
|
- ruff@0.3.4
|
||||||
|
- trivy@0.50.1
|
||||||
|
- trufflehog@3.71.0
|
||||||
|
- yamllint@1.35.1
|
||||||
actions:
|
actions:
|
||||||
disabled:
|
disabled:
|
||||||
- trunk-announce
|
- trunk-announce
|
||||||
|
|||||||
Vendored
-2
@@ -1,6 +1,4 @@
|
|||||||
{
|
{
|
||||||
"python.linting.enabled": true,
|
|
||||||
"python.linting.pylintEnabled": true,
|
|
||||||
"trunk.inlineDecorators": true,
|
"trunk.inlineDecorators": true,
|
||||||
"trunk.inlineDecoratorsForAllExtensions": true,
|
"trunk.inlineDecoratorsForAllExtensions": true,
|
||||||
"trunk.showPreexistingIssues": true,
|
"trunk.showPreexistingIssues": true,
|
||||||
|
|||||||
@@ -35,13 +35,12 @@ import pdf2image
|
|||||||
import PyPDF2
|
import PyPDF2
|
||||||
import requests
|
import requests
|
||||||
import spotipy
|
import spotipy
|
||||||
import tiktoken
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from spotipy.oauth2 import SpotifyClientCredentials
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
|
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
from spotify_dl import youtube as youtube_download
|
|
||||||
from spotify_dl import spotify
|
from spotify_dl import spotify
|
||||||
|
from spotify_dl import youtube as youtube_download
|
||||||
|
|
||||||
Music_Config = TypedDict(
|
Music_Config = TypedDict(
|
||||||
"Music_Config",
|
"Music_Config",
|
||||||
@@ -69,10 +68,6 @@ MEMORY_FIVE_MUZYKA = ""
|
|||||||
SETTINGS_FILE = ""
|
SETTINGS_FILE = ""
|
||||||
ENCODING = ""
|
ENCODING = ""
|
||||||
GRAPHICS_PATH = ""
|
GRAPHICS_PATH = ""
|
||||||
MUZYKA_MOJEGO_LUDU_HISTORIA = 1500
|
|
||||||
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = 15
|
|
||||||
MUZYKA_MOJEGO_LUDU_PLAJLISTA = 30
|
|
||||||
|
|
||||||
# *=========================================== Platform Specific Predefines
|
# *=========================================== Platform Specific Predefines
|
||||||
|
|
||||||
if platform in ("linux", "linux2"):
|
if platform in ("linux", "linux2"):
|
||||||
@@ -80,7 +75,6 @@ if platform in ("linux", "linux2"):
|
|||||||
if "microsoft-standard" in uname().release:
|
if "microsoft-standard" in uname().release:
|
||||||
LOGFILE = "/home/mtuszowski/conjurer/discord.log"
|
LOGFILE = "/home/mtuszowski/conjurer/discord.log"
|
||||||
MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json"
|
MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json"
|
||||||
SYSTEM_GPT_SETTINGS = "/home/mtuszowski/conjurer/system_gpt_settings.json"
|
|
||||||
MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json"
|
MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json"
|
||||||
MUSIC_FOLDER = "/mnt/g/Muzyka/"
|
MUSIC_FOLDER = "/mnt/g/Muzyka/"
|
||||||
SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json"
|
SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json"
|
||||||
@@ -94,7 +88,6 @@ if platform in ("linux", "linux2"):
|
|||||||
else:
|
else:
|
||||||
LOGFILE = "/home/pi/Conjurer/discord.log"
|
LOGFILE = "/home/pi/Conjurer/discord.log"
|
||||||
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
|
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
|
||||||
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
|
|
||||||
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
|
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
|
||||||
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
|
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
|
||||||
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
|
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
|
||||||
@@ -109,7 +102,6 @@ if platform in ("linux", "linux2"):
|
|||||||
elif platform == "win32":
|
elif platform == "win32":
|
||||||
LOGFILE = "discord.log"
|
LOGFILE = "discord.log"
|
||||||
MEMORY_FIVE_SIARA = "pamiec.json"
|
MEMORY_FIVE_SIARA = "pamiec.json"
|
||||||
SYSTEM_GPT_SETTINGS = "system_gpt_settings.json"
|
|
||||||
MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json"
|
MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json"
|
||||||
MUSIC_FOLDER = "G:\\Muzyka\\"
|
MUSIC_FOLDER = "G:\\Muzyka\\"
|
||||||
SETTINGS_FILE = "settings.json"
|
SETTINGS_FILE = "settings.json"
|
||||||
@@ -170,10 +162,6 @@ for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
|
|||||||
if platform == "win32":
|
if platform == "win32":
|
||||||
temp_music_file = temp_music_file.replace("/", "\\")
|
temp_music_file = temp_music_file.replace("/", "\\")
|
||||||
music_file_list.append(temp_music_file)
|
music_file_list.append(temp_music_file)
|
||||||
with open(SYSTEM_GPT_SETTINGS, "r+", encoding=ENCODING) as temp_settings_file:
|
|
||||||
# First we load existing data into a dict.
|
|
||||||
GPT_SETTINGS = json.load(temp_settings_file)
|
|
||||||
|
|
||||||
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as temp_memory_file:
|
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as temp_memory_file:
|
||||||
# First we load existing data into a dict.
|
# First we load existing data into a dict.
|
||||||
MESSAGE_TABLE = json.load(temp_memory_file)
|
MESSAGE_TABLE = json.load(temp_memory_file)
|
||||||
@@ -183,7 +171,6 @@ with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as temp_music_memory_file
|
|||||||
with open(SETTINGS_FILE, "r", encoding=ENCODING) as f_settings_file:
|
with open(SETTINGS_FILE, "r", encoding=ENCODING) as f_settings_file:
|
||||||
data = json.load(f_settings_file)
|
data = json.load(f_settings_file)
|
||||||
word_reactions = data["word_reactions"]
|
word_reactions = data["word_reactions"]
|
||||||
cyclic_words = data["cyclic_words"]
|
|
||||||
historia_fabryczki = data["fabryczka"]
|
historia_fabryczki = data["fabryczka"]
|
||||||
for key in word_reactions:
|
for key in word_reactions:
|
||||||
word_reactions[key][2] = datetime.now()
|
word_reactions[key][2] = datetime.now()
|
||||||
@@ -200,6 +187,7 @@ async def on_ready():
|
|||||||
logger.debug("%s has connected to Discord!", client.user)
|
logger.debug("%s has connected to Discord!", client.user)
|
||||||
await client.change_presence(activity=discord.Game(name="Axe Throwing Darts"))
|
await client.change_presence(activity=discord.Game(name="Axe Throwing Darts"))
|
||||||
await client.tree.sync()
|
await client.tree.sync()
|
||||||
|
# await tree.sync(guild=discord.Object(id=Your guild id))
|
||||||
await check()
|
await check()
|
||||||
|
|
||||||
|
|
||||||
@@ -278,33 +266,26 @@ async def on_message(message):
|
|||||||
word_reactions[word][2] = datetime.now()
|
word_reactions[word][2] = datetime.now()
|
||||||
|
|
||||||
# TODO: drobne literówki, mentiony, spacja przed dwukropkiem. napraw.
|
# TODO: drobne literówki, mentiony, spacja przed dwukropkiem. napraw.
|
||||||
kondziu_mentioned = False
|
|
||||||
for mention in message.mentions:
|
|
||||||
if mention == client.user:
|
|
||||||
kondziu_mentioned = True
|
|
||||||
|
|
||||||
if kondziu_mentioned or "conjurer:" in message.content:
|
if "conjurer:" in message.content:
|
||||||
async with channel.typing():
|
async with channel.typing():
|
||||||
logger.debug("Procedura chatu")
|
logger.debug("Procedura chatu")
|
||||||
|
|
||||||
message.content = message.content.replace("conjurer: ", "")
|
message.content = message.content.replace("conjurer: ", "")
|
||||||
|
|
||||||
|
prompt = message.content
|
||||||
|
|
||||||
if message.author.nick:
|
if message.author.nick:
|
||||||
username = message.author.nick
|
username = message.author.nick
|
||||||
else:
|
else:
|
||||||
username = message.author.name
|
username = message.author.name
|
||||||
vykidailo = False
|
vykidailo = False
|
||||||
bartender = False
|
bartender = False
|
||||||
if kondziu_mentioned:
|
|
||||||
prompt = message.clean_content
|
|
||||||
else:
|
|
||||||
prompt = message.content
|
|
||||||
for role in message.author.roles:
|
for role in message.author.roles:
|
||||||
if role.name == "Vykidailo":
|
if role.name == "Vykidailo":
|
||||||
vykidailo = True
|
vykidailo = True
|
||||||
if role.name == "Bartender":
|
if role.name == "Bartender":
|
||||||
bartender = True
|
bartender = True
|
||||||
global MESSAGE_TABLE # pylint: disable=global-statement
|
global MESSAGE_TABLE # pylint: disable=global-statement
|
||||||
|
|
||||||
result, MESSAGE_TABLE = await handle_response(
|
result, MESSAGE_TABLE = await handle_response(
|
||||||
prompt, vykidailo, bartender, MESSAGE_TABLE, username, False
|
prompt, vykidailo, bartender, MESSAGE_TABLE, username, False
|
||||||
)
|
)
|
||||||
@@ -335,29 +316,6 @@ async def on_message(message):
|
|||||||
|
|
||||||
# *=========================================== Define Functions
|
# *=========================================== Define Functions
|
||||||
|
|
||||||
def num_tokens_from_string(message, model):
|
|
||||||
"""
|
|
||||||
The function takes a string message and a model as input and returns the number of tokens in the
|
|
||||||
message according to the given model.
|
|
||||||
|
|
||||||
:param message: A string containing the message or text from which you want to count the number of
|
|
||||||
tokens
|
|
||||||
:param model: The model parameter refers to a language model or tokenizer that can be used to
|
|
||||||
tokenize the input string. It could be a pre-trained model or a custom tokenizer
|
|
||||||
"""
|
|
||||||
tokens_per_message = 3
|
|
||||||
tokens_per_name = 1
|
|
||||||
chat_gpt_encoding = tiktoken.encoding_for_model(model)
|
|
||||||
|
|
||||||
num_tokens = 0
|
|
||||||
num_tokens += tokens_per_message
|
|
||||||
for keys, values in message.items():
|
|
||||||
num_tokens += len(chat_gpt_encoding.encode(values))
|
|
||||||
if keys == "role":
|
|
||||||
num_tokens += tokens_per_name
|
|
||||||
num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
|
|
||||||
return num_tokens
|
|
||||||
|
|
||||||
|
|
||||||
async def connect(ctx, arg=None):
|
async def connect(ctx, arg=None):
|
||||||
"""
|
"""
|
||||||
@@ -490,16 +448,8 @@ async def play(ctx, zamawial=None, arg=None):
|
|||||||
|
|
||||||
async def check():
|
async def check():
|
||||||
"""Funkcja sprawdzająca czy grać następny kawałek."""
|
"""Funkcja sprawdzająca czy grać następny kawałek."""
|
||||||
last_spontaneous_call = datetime.now()
|
|
||||||
while True:
|
while True:
|
||||||
tdelta = datetime.now() - last_spontaneous_call
|
# TODO: Tu dołożyć skanowanie rozmiaru pliku logowania oraz plików pamięci i przenoszenie ich na większy dysk.
|
||||||
tdelta = tdelta.total_seconds()
|
|
||||||
if tdelta > 34000:
|
|
||||||
channel = client.get_channel(1062047571557744721)
|
|
||||||
last_spontaneous_call = datetime.now()
|
|
||||||
with channel.typing():
|
|
||||||
message = get_random_cyclic_message()
|
|
||||||
await channel.send(message)
|
|
||||||
# trunk-ignore(codespell/misspelled)
|
# trunk-ignore(codespell/misspelled)
|
||||||
# TODO: dlaczego sie tu wypierdala
|
# TODO: dlaczego sie tu wypierdala
|
||||||
if client.voice_clients:
|
if client.voice_clients:
|
||||||
@@ -567,19 +517,7 @@ async def check():
|
|||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
async def get_random_cyclic_message():
|
|
||||||
"""
|
|
||||||
The function `get_random_cyclic_message` returns a random cyclic message from a list of cyclic
|
|
||||||
words.
|
|
||||||
:return: a random cyclic message from the list `cyclic_words`.
|
|
||||||
"""
|
|
||||||
messnum = random.randint(0, len(cyclic_words)-1)
|
|
||||||
return cyclic_words[messnum][0]
|
|
||||||
|
|
||||||
|
|
||||||
# trunk-ignore(pylint/R0914)
|
|
||||||
# trunk-ignore(pylint/R0913)
|
# trunk-ignore(pylint/R0913)
|
||||||
# trunk-ignore(pylint/R0915)
|
|
||||||
async def handle_response(prompt, vykidailo, bartender, history, username, music):
|
async def handle_response(prompt, vykidailo, bartender, history, username, music):
|
||||||
"""
|
"""
|
||||||
Handle responses by appending them to a history, use OpenAI to
|
Handle responses by appending them to a history, use OpenAI to
|
||||||
@@ -622,49 +560,22 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
|
|||||||
# convert back to json.
|
# convert back to json.
|
||||||
json.dump(file_data, file_memory, indent=4)
|
json.dump(file_data, file_memory, indent=4)
|
||||||
history = []
|
history = []
|
||||||
history.append(GPT_SETTINGS[0])
|
# * append bo pierwszy index
|
||||||
chat_gpt_config_request_size = num_tokens_from_string(GPT_SETTINGS[0], "gpt-4")
|
# * extend bo 20 ostatnich
|
||||||
|
|
||||||
for (slowo, reakcja) in word_reactions.items():
|
|
||||||
if not reakcja[3]:
|
|
||||||
content = "Kiedy słyszysz " + slowo + " to reagujesz lub dzieje się to " + reakcja[0]
|
|
||||||
temp = {"role": "system", "content": content}
|
|
||||||
chat_gpt_config_request_size += num_tokens_from_string(temp, "gpt-4")
|
|
||||||
history.append(temp)
|
|
||||||
|
|
||||||
final_prompt = username + ":" + prompt
|
|
||||||
logger.info("Rozmiar zapytania przed dodaniem historii %s", chat_gpt_config_request_size)
|
|
||||||
if music:
|
if music:
|
||||||
algorithm = "gpt-3.5-turbo-16k"
|
history.append(message_table_muzyka[0])
|
||||||
table = message_table_muzyka
|
history.extend(message_table_muzyka[-20:])
|
||||||
token_amount = 10700
|
|
||||||
else:
|
else:
|
||||||
table = MESSAGE_TABLE
|
history.append(MESSAGE_TABLE[0])
|
||||||
algorithm = "gpt-4"
|
history.extend(MESSAGE_TABLE[-20:])
|
||||||
token_amount = 7000
|
|
||||||
|
|
||||||
prompt_gpt_request_size = num_tokens_from_string({"role": "user", "content": final_prompt}, "gpt-4")
|
|
||||||
temptable = []
|
|
||||||
for i in reversed(table):
|
|
||||||
temp_token = num_tokens_from_string(i, "gpt-4")
|
|
||||||
logger.info("Rozmiar zapytania %s prompt %s temp %s", chat_gpt_config_request_size, prompt_gpt_request_size, temp_token)
|
|
||||||
if chat_gpt_config_request_size < token_amount + prompt_gpt_request_size + temp_token:
|
|
||||||
temptable.insert(1, i)
|
|
||||||
chat_gpt_config_request_size += temp_token
|
|
||||||
history.extend(temptable)
|
|
||||||
temp = {"role": "user", "content": final_prompt}
|
|
||||||
history.append(temp)
|
|
||||||
logger.info("Rozmiar zapytania po wyslaniu %s", chat_gpt_config_request_size)
|
|
||||||
|
|
||||||
response = await openai.ChatCompletion.acreate(
|
|
||||||
model=algorithm, messages=history
|
|
||||||
)
|
|
||||||
logger.info("Historia wysłana:")
|
logger.info("Historia wysłana:")
|
||||||
logger.info(history)
|
logger.debug(history)
|
||||||
await asyncio.sleep(15)
|
response = await openai.ChatCompletion.acreate(
|
||||||
|
model="gpt-3.5-turbo", messages=history
|
||||||
|
)
|
||||||
|
await asyncio.sleep(10)
|
||||||
result = ""
|
result = ""
|
||||||
logger.debug("Odpowiedzi")
|
logger.debug("Odpowiedzi")
|
||||||
logger.info(response)
|
|
||||||
logger.debug(response.choices)
|
logger.debug(response.choices)
|
||||||
for choice in response.choices:
|
for choice in response.choices:
|
||||||
result += choice.message.content
|
result += choice.message.content
|
||||||
@@ -845,42 +756,10 @@ async def async_iterator_generator(range_of_iterable):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
async def get_stats(ctx, history_limit):
|
|
||||||
"""
|
|
||||||
The `get_stats` function retrieves the message history of a specific channel and counts the
|
|
||||||
frequency of each word in the messages.
|
|
||||||
|
|
||||||
:param ctx: The `ctx` parameter is an object that represents the context of the command being
|
|
||||||
executed. It contains information such as the message, the author, the server, and other relevant
|
|
||||||
details
|
|
||||||
:param history_limit: The `history_limit` parameter is the maximum number of messages to retrieve
|
|
||||||
from the channel history. It determines how far back in time the statistics will be calculated
|
|
||||||
:return: The function `get_stats` returns a dictionary `stats` that contains the frequency count of
|
|
||||||
words found in the messages from the specified channel.
|
|
||||||
"""
|
|
||||||
channel_id = 1062047367337095268
|
|
||||||
async with ctx.typing():
|
|
||||||
stats = {}
|
|
||||||
channel = client.get_channel(channel_id)
|
|
||||||
messages = [message async for message in channel.history(limit=history_limit)]
|
|
||||||
# traverse the iterable of awaitables
|
|
||||||
for message in messages:
|
|
||||||
# await and get the result from the awaitable
|
|
||||||
result = message.content
|
|
||||||
words = result.split()
|
|
||||||
for word in words:
|
|
||||||
if word in stats:
|
|
||||||
stats[word] += 1
|
|
||||||
else:
|
|
||||||
stats[word] = 1
|
|
||||||
for name, how_many in stats.items():
|
|
||||||
yield name, how_many
|
|
||||||
|
|
||||||
|
|
||||||
# trunk-ignore(pylint/R0914)
|
# trunk-ignore(pylint/R0914)
|
||||||
# trunk-ignore(pylint/R0915)
|
# trunk-ignore(pylint/R0915)
|
||||||
# trunk-ignore(pylint/R0912)
|
# trunk-ignore(pylint/R0912)
|
||||||
async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
async def wyszukaj(ctx, how_many=0):
|
||||||
"""
|
"""
|
||||||
Take in a context object and an optional integer parameter "how_many" and perform search
|
Take in a context object and an optional integer parameter "how_many" and perform search
|
||||||
operation on music library.
|
operation on music library.
|
||||||
@@ -894,10 +773,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
|||||||
"""
|
"""
|
||||||
# TODO: Potem dorobić wyszukiwania po kawałkach słów
|
# TODO: Potem dorobić wyszukiwania po kawałkach słów
|
||||||
# i sieć neuronową z możliwością wyrażenia opinii o dopasowaniu.
|
# i sieć neuronową z możliwością wyrażenia opinii o dopasowaniu.
|
||||||
if slowa_kluczowe:
|
word_list = ctx.message.content.split()
|
||||||
word_list = slowa_kluczowe
|
|
||||||
else:
|
|
||||||
word_list = ctx.message.content.split()
|
|
||||||
logger.info("Wyszukuje")
|
logger.info("Wyszukuje")
|
||||||
search_weight = []
|
search_weight = []
|
||||||
for _ in range(len(music_file_list)):
|
for _ in range(len(music_file_list)):
|
||||||
@@ -908,11 +784,11 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
|||||||
skip_start = 2
|
skip_start = 2
|
||||||
else:
|
else:
|
||||||
skip_start = 1
|
skip_start = 1
|
||||||
async for word in async_iterator_generator(word_list[skip_start:]):
|
for word in word_list[skip_start:]:
|
||||||
token_weight = len(word)
|
token_weight = len(word)
|
||||||
logger.info("Słowo kluczowe: %s", word)
|
logger.info("Słowo kluczowe: %s", word)
|
||||||
itr = 0
|
itr = 0
|
||||||
async for file in async_iterator_generator(music_file_list):
|
for file in music_file_list:
|
||||||
file = file.split(SEPARATOR_FILE_PATH)
|
file = file.split(SEPARATOR_FILE_PATH)
|
||||||
|
|
||||||
char_remove = [
|
char_remove = [
|
||||||
@@ -938,9 +814,9 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
|||||||
"mp3",
|
"mp3",
|
||||||
]
|
]
|
||||||
all_words = []
|
all_words = []
|
||||||
async for f_iter in async_iterator_generator(file):
|
for f_iter in file:
|
||||||
async for char in async_iterator_generator(char_remove):
|
for char in char_remove:
|
||||||
f_iter = await remove_characters(f_iter, char)
|
f_iter = f_iter.replace(char, "")
|
||||||
tmp = f_iter.split()
|
tmp = f_iter.split()
|
||||||
all_words.extend(tmp)
|
all_words.extend(tmp)
|
||||||
pingu = 1
|
pingu = 1
|
||||||
@@ -950,7 +826,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
|||||||
else:
|
else:
|
||||||
skip = 4
|
skip = 4
|
||||||
matched_times = 1
|
matched_times = 1
|
||||||
async for itm in async_iterator_generator(all_words[skip:]):
|
for itm in all_words[skip:]:
|
||||||
pingu += 1
|
pingu += 1
|
||||||
pattern = ".*" + word + ".*"
|
pattern = ".*" + word + ".*"
|
||||||
if re.match(pattern, itm, re.IGNORECASE):
|
if re.match(pattern, itm, re.IGNORECASE):
|
||||||
@@ -986,18 +862,6 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
|
|||||||
return return_list
|
return return_list
|
||||||
|
|
||||||
|
|
||||||
async def remove_characters(string, character):
|
|
||||||
"""
|
|
||||||
The `remove_characters` function removes all occurrences of a specified character from a given
|
|
||||||
string.
|
|
||||||
|
|
||||||
:param string: The string parameter is the input string from which characters will be removed
|
|
||||||
:param character: The character parameter is the character that you want to remove from the string
|
|
||||||
:return: a new string where all occurrences of the specified character have been removed.
|
|
||||||
"""
|
|
||||||
return string.replace(character, "")
|
|
||||||
|
|
||||||
|
|
||||||
async def max_weight(lista):
|
async def max_weight(lista):
|
||||||
"""
|
"""
|
||||||
Take a list of weights and return the maximum weight.
|
Take a list of weights and return the maximum weight.
|
||||||
@@ -1455,7 +1319,7 @@ async def zrob_mi_plejliste(ctx):
|
|||||||
if metadata.tag.title:
|
if metadata.tag.title:
|
||||||
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
|
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
|
||||||
else:
|
else:
|
||||||
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n"
|
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
if len(reply) > 1800:
|
if len(reply) > 1800:
|
||||||
@@ -1625,14 +1489,7 @@ async def get_image_stable_diffusion(ctx):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# trunk-ignore(mypy/arg-type)
|
# @client.hybrid_command()
|
||||||
@client.hybrid_command(
|
|
||||||
name="zagraj_muzyke_mego_ludu",
|
|
||||||
description="Gra muzyke wyszukana na bazie tematow konwersacji na kanale NZ",
|
|
||||||
guild=discord.Object(id=664789470779932693),
|
|
||||||
)
|
|
||||||
# trunk-ignore(pylint/R0912)
|
|
||||||
# trunk-ignore(pylint/R0915)
|
|
||||||
async def zagraj_muzyke_mego_ludu(ctx):
|
async def zagraj_muzyke_mego_ludu(ctx):
|
||||||
"""
|
"""
|
||||||
Play completeley random playlist based on messaging history.
|
Play completeley random playlist based on messaging history.
|
||||||
@@ -1642,117 +1499,9 @@ async def zagraj_muzyke_mego_ludu(ctx):
|
|||||||
channel, the author, and other relevant details. In this case, it is being passed as a parameter to
|
channel, the author, and other relevant details. In this case, it is being passed as a parameter to
|
||||||
the `get_image
|
the `get_image
|
||||||
"""
|
"""
|
||||||
stats = {}
|
|
||||||
if ctx:
|
|
||||||
logger.info("Zagraj muzyke mego ludu: wywolane")
|
|
||||||
stat_iter = get_stats(ctx, MUZYKA_MOJEGO_LUDU_HISTORIA)
|
|
||||||
async for name, how_many in stat_iter:
|
|
||||||
if len(name) > 3:
|
|
||||||
stats[name] = how_many
|
|
||||||
|
|
||||||
sorted_stats = sorted(stats.items(), key=lambda x: x[1])
|
|
||||||
logger.info("Zagraj muzyke mego ludu:zebrano statystyki")
|
|
||||||
key_words = []
|
|
||||||
for stat in sorted_stats:
|
|
||||||
key_words.append(stat[0])
|
|
||||||
logger.info(sorted_stats[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE])
|
|
||||||
logger.info(key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE])
|
|
||||||
logger.info(sorted_stats[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
|
|
||||||
logger.info(key_words[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
|
|
||||||
|
|
||||||
final_key_words = key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]
|
|
||||||
final_key_words.extend(key_words[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
|
|
||||||
reply = "Wygenerowana plejlista:\n"
|
|
||||||
async with ctx.typing():
|
|
||||||
logger.info("Zaczynam szukać timestamp %s", datetime.now())
|
|
||||||
search_time_glob = datetime.now()
|
|
||||||
file = await wyszukaj(ctx=ctx, how_many=MUZYKA_MOJEGO_LUDU_PLAJLISTA, slowa_kluczowe=final_key_words)
|
|
||||||
logger.info("Zagraj muzyke mego ludu:wygenerowano plejliste")
|
|
||||||
logger.info(file)
|
|
||||||
logger.info(
|
|
||||||
"Koniec szukania(timestamp %s zajęło %s",
|
|
||||||
datetime.now(),
|
|
||||||
datetime.now() - search_time_glob,
|
|
||||||
)
|
|
||||||
index = 1
|
|
||||||
if file:
|
|
||||||
for plik in file:
|
|
||||||
global MUZYKA # pylint: disable=global-variable-not-assigned
|
|
||||||
MUZYKA["queue"].insert(0, plik[1])
|
|
||||||
MUZYKA["requestor"].insert(0, ctx.author)
|
|
||||||
metadata = eyed3.load(plik[1])
|
|
||||||
if metadata and metadata.tag:
|
|
||||||
if metadata.tag.title:
|
|
||||||
reply += f"{index} {metadata.tag.title}"
|
|
||||||
else:
|
|
||||||
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
|
|
||||||
|
|
||||||
if metadata.tag.artist:
|
|
||||||
reply += f" wykonawcy {metadata.tag.artist}"
|
|
||||||
if metadata.tag.album:
|
|
||||||
reply += f" z albumu {metadata.tag.album}"
|
|
||||||
if metadata.tag.title:
|
|
||||||
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
|
|
||||||
else:
|
|
||||||
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n"
|
|
||||||
|
|
||||||
index += 1
|
|
||||||
if len(reply) > 1800:
|
|
||||||
await ctx.send(reply)
|
|
||||||
reply = ""
|
|
||||||
else:
|
|
||||||
await ctx.send(
|
|
||||||
"Obawiam się że nie mogę nic znaleźć u siebie. Spróbuj komendy '$dej_co_ze_spotifaja' jeśli masz link"
|
|
||||||
)
|
|
||||||
await ctx.send(reply)
|
|
||||||
logger.info("Plejlista zrobiona")
|
|
||||||
|
|
||||||
|
|
||||||
# trunk-ignore(mypy/arg-type)
|
|
||||||
@client.hybrid_command(
|
|
||||||
name="parametry_muzyki_mego_ludu",
|
|
||||||
description="Konfiguruje komende zagraj muzyke mojego ludu",
|
|
||||||
guild=discord.Object(id=664789470779932693),
|
|
||||||
)
|
|
||||||
async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych=15, jak_dluga_plejlista=30):
|
|
||||||
"""
|
|
||||||
The function `parametry_muzyki_mego_ludu` sets global variables for the number of history entries,
|
|
||||||
number of keywords, and length of playlist for a music application.
|
|
||||||
|
|
||||||
:param ctx: The `ctx` parameter is typically used in Discord.py, a Python library for creating
|
|
||||||
Discord bots. It represents the context of the command being executed, including information about
|
|
||||||
the message, the server, and the user who invoked the command
|
|
||||||
:param ile_historii: The parameter "ile_historii" represents the number of history items for the
|
|
||||||
music playlist, defaults to 1500 (optional)
|
|
||||||
:param ile_slow_kluczowych: The parameter "ile_slow_kluczowych" represents the number of keywords or
|
|
||||||
key phrases related to music that you want to include in your analysis or search, defaults to 30
|
|
||||||
(optional)
|
|
||||||
:param jak_dluga_plejlista: The parameter "jak_dluga_plejlista" determines the length of the
|
|
||||||
playlist. It specifies how many songs should be included in the playlist, defaults to 30 (optional)
|
|
||||||
"""
|
|
||||||
|
|
||||||
if ctx:
|
if ctx:
|
||||||
async with ctx.typing():
|
pass
|
||||||
# if ':' in ile_historii:
|
|
||||||
# _, _, ile_historii = ile_historii.partition(':')
|
|
||||||
# if ':' in ile_slow_kluczowych:
|
|
||||||
# _, _, ile_slow_kluczowych = ile_slow_kluczowych.partition(':')
|
|
||||||
# if ':' in jak_dluga_plejlista:
|
|
||||||
# _, _, jak_dluga_plejlista = jak_dluga_plejlista.partition(':')
|
|
||||||
try:
|
|
||||||
global MUZYKA_MOJEGO_LUDU_HISTORIA # pylint: disable=global-statement
|
|
||||||
global MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE # pylint: disable=global-statement
|
|
||||||
global MUZYKA_MOJEGO_LUDU_PLAJLISTA # pylint: disable=global-statement
|
|
||||||
logger.info("Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s", MUZYKA_MOJEGO_LUDU_HISTORIA, MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE, MUZYKA_MOJEGO_LUDU_PLAJLISTA)
|
|
||||||
ctx.send(f"Dotychczasowe wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}")
|
|
||||||
MUZYKA_MOJEGO_LUDU_HISTORIA = ile_historii
|
|
||||||
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = ile_slow_kluczowych
|
|
||||||
MUZYKA_MOJEGO_LUDU_PLAJLISTA = jak_dluga_plejlista
|
|
||||||
logger.info("Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s", MUZYKA_MOJEGO_LUDU_HISTORIA, MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE, MUZYKA_MOJEGO_LUDU_PLAJLISTA)
|
|
||||||
ctx.send(f"Zmienione wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}")
|
|
||||||
except discord.ext.commands.errors.BadArgument as exce:
|
|
||||||
ctx.send("Spierdalaj")
|
|
||||||
logger.info(exce)
|
|
||||||
|
|
||||||
|
|
||||||
# *================================== Run
|
# *================================== Run
|
||||||
|
|||||||
+1707
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,58 @@
|
|||||||
|
# trunk-ignore-all(pylint/C0301)
|
||||||
|
|
||||||
|
FILE_SIZE_LIMIT = 100000 * 1024
|
||||||
|
SOURCE = "/mnt/n/scimag_2020-05-30.sql/scimag_2020-05-30.sql"
|
||||||
|
OUTPUT_FOLDER = "/mnt/n/scimag_2020-05-30.sql/"
|
||||||
|
OUTPUT_FILE_SCHEMA = "_scimag_chunk.sql"
|
||||||
|
|
||||||
|
|
||||||
|
def smart_write(lines, file):
|
||||||
|
"""
|
||||||
|
The function `smart_write` encodes the input lines to UTF-8, writes them to a file, and returns the
|
||||||
|
size of the encoded bytes.
|
||||||
|
|
||||||
|
:param lines: The `lines` parameter in the `smart_write` function is a string that contains the text
|
||||||
|
content that you want to write to a file
|
||||||
|
:param file: The `file` parameter in the `smart_write` function is expected to be a file object that
|
||||||
|
has been opened in write mode. This file object will be used to write the encoded `lines` to a file
|
||||||
|
:return: The function `smart_write` returns the size of the encoded bytes of the input `lines` in
|
||||||
|
bytes.
|
||||||
|
"""
|
||||||
|
encoded_bytes = lines.encode("utf-8")
|
||||||
|
size_in_bytes = len(encoded_bytes)
|
||||||
|
file.write(lines)
|
||||||
|
|
||||||
|
return size_in_bytes
|
||||||
|
|
||||||
|
|
||||||
|
def cut_my_life_into_pieces(source, output_folder, output_file):
|
||||||
|
"""
|
||||||
|
The function `cut_my_life_into_pieces` reads a source file, splits its content into smaller parts
|
||||||
|
based on a file size limit, and writes these parts to separate output files in a specified output
|
||||||
|
folder.
|
||||||
|
|
||||||
|
:param source: The `source` parameter in the `cut_my_life_into_pieces` function is the file path of
|
||||||
|
the source file that you want to process and split into smaller pieces
|
||||||
|
:param output_folder: The `output_folder` parameter in the `cut_my_life_into_pieces` function
|
||||||
|
represents the directory where the output files will be saved. It should be a string that specifies
|
||||||
|
the path to the folder where you want to store the output files generated by the function. For
|
||||||
|
example, it could be something like
|
||||||
|
:param output_file: The `output_file` parameter in the `cut_my_life_into_pieces` function represents
|
||||||
|
the name of the output file that will be created for each segment of the source file. It will be
|
||||||
|
appended with a number to differentiate between different segments
|
||||||
|
"""
|
||||||
|
with open(source, encoding="utf-8") as infile:
|
||||||
|
output_size = 0
|
||||||
|
output_no = 0
|
||||||
|
|
||||||
|
for line in infile:
|
||||||
|
if output_size > FILE_SIZE_LIMIT:
|
||||||
|
output_no += 1
|
||||||
|
output_size = 0
|
||||||
|
op_file_name = str(output_no) + output_file
|
||||||
|
with open(
|
||||||
|
output_folder + op_file_name,
|
||||||
|
"a",
|
||||||
|
encoding="utf-8",
|
||||||
|
) as op_file:
|
||||||
|
output_size += smart_write(line, op_file)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
Kluczowe jest zeby po każdej linijce pokazywał która to jest, oraz po pliku
|
||||||
|
"""
|
||||||
|
|
||||||
|
import netrc
|
||||||
|
|
||||||
|
import mysql.connector
|
||||||
|
|
||||||
|
NETRC_FILE = "/home/mtuszowski/.netrc"
|
||||||
|
|
||||||
|
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||||
|
REMOTE_HOST_NAME = "sql_localhost"
|
||||||
|
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
|
||||||
|
|
||||||
|
mydb = mysql.connector.connect(
|
||||||
|
host="localhost", user="root", password="root", database="scihubdois"
|
||||||
|
)
|
||||||
|
mycursor = mydb.cursor()
|
||||||
|
|
||||||
|
mycursor.execute("SELECT * FROM scimag")
|
||||||
|
for x in mycursor:
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
|
||||||
|
file_list = ""
|
||||||
|
for file in file_list:
|
||||||
|
|
||||||
|
with open(
|
||||||
|
"/mnt/n/scimag_2020-05-30.sql/{}".format(file), encoding="utf-8"
|
||||||
|
) as infile:
|
||||||
|
pass
|
||||||
|
result = mycursor.execute("SHOW databases")
|
||||||
|
# trunk-ignore(mypy/union-attr)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from pathlib import Path, PurePath
|
||||||
|
from platform import uname
|
||||||
|
from sys import platform
|
||||||
|
MUSIC_FOLDER = ""
|
||||||
|
if platform in ("linux", "linux2"):
|
||||||
|
SEPARATOR_FILE_PATH = "/"
|
||||||
|
if "microsoft-standard" in uname().release:
|
||||||
|
LOGFILE = "/home/mtuszowski/conjurer/discord_mus_service.log"
|
||||||
|
MUSIC_FOLDER = "/mnt/g/Muzyka/"
|
||||||
|
NETRC_FILE = "/home/mtuszowski/.netrc"
|
||||||
|
LOGSTORE = "/home/mtuszowski/conjurer/logs/"
|
||||||
|
ENCODING = "utf-8"
|
||||||
|
GRAPHICS_PATH = "/home/mtuszowski/conjurer/Conjurer_graphics/"
|
||||||
|
|
||||||
|
else:
|
||||||
|
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
|
||||||
|
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
|
||||||
|
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
|
||||||
|
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
|
||||||
|
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
|
||||||
|
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
|
||||||
|
NETRC_FILE = "/home/pi/.netrc"
|
||||||
|
LOGSTORE = "/home/pi/RetroPie/logs/"
|
||||||
|
ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json"
|
||||||
|
ENCODING = "utf-8"
|
||||||
|
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/"
|
||||||
|
DIR_PATH_SADOX = "/home/pi/RetroPie/Fansadox/"
|
||||||
|
|
||||||
|
music_file_list = []
|
||||||
|
for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
|
||||||
|
temp_music_file = mp3_item.as_posix()
|
||||||
|
if platform == "win32":
|
||||||
|
temp_music_file = temp_music_file.replace("/", "\\")
|
||||||
|
music_file_list.append(temp_music_file)
|
||||||
|
|
||||||
+1
-1
@@ -211,7 +211,7 @@
|
|||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
],
|
],
|
||||||
"burdel": [
|
"burdel\\b": [
|
||||||
"Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.",
|
"Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.",
|
||||||
15.0,
|
15.0,
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"""
|
||||||
|
This Python code snippet is connecting to a MySQL database
|
||||||
|
using the `mysql.connector` library and fetching data from a table named `scimag`
|
||||||
|
Here is a breakdown of what the code is doing:
|
||||||
|
"""
|
||||||
|
|
||||||
|
import netrc
|
||||||
|
|
||||||
|
import mysql.connector
|
||||||
|
|
||||||
|
NETRC_FILE = "/home/mtuszowski/.netrc"
|
||||||
|
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||||
|
REMOTE_HOST_NAME = "192.168.1.192"
|
||||||
|
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
|
||||||
|
|
||||||
|
mydb = mysql.connector.connect(
|
||||||
|
host=REMOTE_HOST_NAME,
|
||||||
|
user=authTokens[0],
|
||||||
|
password=authTokens[2],
|
||||||
|
database="scihubdois",
|
||||||
|
)
|
||||||
|
mycursor = mydb.cursor()
|
||||||
|
|
||||||
|
mycursor.execute("SELECT * FROM scimag WHERE Title Like 'spider%'")
|
||||||
|
for x in mycursor:
|
||||||
|
print(x)
|
||||||
Reference in New Issue
Block a user