mirror of
https://github.com/appinfosapienza/so-un-bot.git
synced 2025-05-05 19:52:34 +02:00
move legacy code to separate branch
This commit is contained in:
parent
68a30c8ee6
commit
11b4c48c3a
3528 changed files with 14477 additions and 53258 deletions
17
Utils/check-ingsw-photos.sh
Executable file
17
Utils/check-ingsw-photos.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
SEARCHDIR="./Ingegneria del Software/"
|
||||
|
||||
echo "Invalid URLs:"
|
||||
|
||||
for img in `grep "img" "$SEARCHDIR" -R | sed -E 's/^(.*?)\.txt\:img\=//'`; do
|
||||
img=$(echo "$img"|tr -d '\n'|tr -d '\r')
|
||||
curl -I "$img" 2>/dev/null | \
|
||||
grep -i "Content-Type: image/" >/dev/null
|
||||
if [ "$?" -ne 0 ]; then
|
||||
(
|
||||
cd "$SEARCHDIR"
|
||||
grep "$img" . -R
|
||||
)
|
||||
fi
|
||||
done
|
65
Utils/find_duplicates.py
Normal file
65
Utils/find_duplicates.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
# A python helper script that finds duplicated questions
|
||||
# and deletes them.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
path = input("Specify the path: ")
|
||||
|
||||
quests = list(os.walk(path))[0][1]
|
||||
|
||||
m = {}
|
||||
|
||||
print("Loading questions...")
|
||||
|
||||
for q in quests:
|
||||
qq = open(path + "/" + q + "/quest.txt", "r").read()
|
||||
if qq.startswith("img=") and "\n" in qq:
|
||||
qq = qq[qq.index("\n"):]
|
||||
|
||||
cc = open(path + "/" + q + "/correct.txt", "r").read()
|
||||
if cc.startswith("img=") and "\n" in cc:
|
||||
cc = cc[cc.index("\n"):]
|
||||
|
||||
qq = qq + cc
|
||||
|
||||
qq = qq.replace("\n", "")
|
||||
qq = qq.replace("<pre>", "")
|
||||
qq = qq.replace("<code>", "")
|
||||
qq = qq.replace("</pre>", "")
|
||||
qq = qq.replace("</code>", "")
|
||||
qq = qq.replace("'", "")
|
||||
qq = qq.replace("à", "a")
|
||||
qq = qq.replace("è", "e")
|
||||
qq = qq.replace("ì", "i")
|
||||
qq = qq.replace("ò", "o")
|
||||
qq = qq.replace("ù", "u")
|
||||
qq = qq.replace(" ", "")
|
||||
m[q] = qq
|
||||
|
||||
print("Comparing questions...")
|
||||
|
||||
rev_dict = {}
|
||||
|
||||
for key, value in m.items():
|
||||
rev_dict.setdefault(value, set()).add(key)
|
||||
|
||||
|
||||
result = [values for key, values in rev_dict.items()
|
||||
if len(values) > 1]
|
||||
|
||||
if result:
|
||||
print("Duplicate questions:", str(result))
|
||||
else:
|
||||
print("There are no duplicates!")
|
||||
exit()
|
||||
|
||||
for dup in result:
|
||||
#delete the duplicates
|
||||
ld = list(dup)
|
||||
for i in range(len(ld)):
|
||||
if i == 0:
|
||||
print("Keeping " + ld[i])
|
||||
continue
|
||||
print("Deleting", ld[i])
|
||||
shutil.rmtree(path + "/" + ld[i])
|
22
Utils/make_questions.py
Normal file
22
Utils/make_questions.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# A python helper tool to generate questions with the directory tree format
|
||||
|
||||
import os
|
||||
|
||||
prefix = input("Specify a prefix (default is no prefix): ")
|
||||
separator = input("Specify a separator (default is no separator): ")
|
||||
current = int(input("Number of the next question: "))
|
||||
path = input("Specify the path: ")
|
||||
|
||||
while True:
|
||||
dirname = path + "/" + prefix + separator + str(current)
|
||||
os.mkdir(dirname)
|
||||
open(dirname + "/quest.txt", 'a').close()
|
||||
os.system("\"" + dirname + "/quest.txt" + "\"")
|
||||
open(dirname + "/correct.txt", 'a').close()
|
||||
os.system("\"" + dirname + "/correct.txt" + "\"")
|
||||
open(dirname + "/wrong 1.txt", 'a').close()
|
||||
os.system("\"" + dirname + "/wrong 1.txt" + "\"")
|
||||
open(dirname + "/wrong 2.txt", 'a').close()
|
||||
os.system("\"" + dirname + "/wrong 2.txt" + "\"")
|
||||
|
||||
current += 1
|
12
Utils/moodle-scraper/README.md
Normal file
12
Utils/moodle-scraper/README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
### Moodle Scraper
|
||||
|
||||
Web scraper in Python per salvare un quiz Moodle in un formato compatibile con il bot.
|
||||
|
||||
Per far funzionare lo scraper, è necessario creare un file .env nella directory dello scraper e inserire rispettivamente:
|
||||
|
||||
USER = Matricola
|
||||
PASSWORD = Password di Infostud
|
||||
|
||||
Infine inserire il chromedriver sempre nella directory dello scraper.
|
||||
|
||||
Una volta lanciato lo script, le domande verranno inserite formattate in cartelle che verranno create all'interno della cartella Scraper. Fare attenzione al fatto che le domande con immagini non sono gestite e dovranno comunque essere inserite a mano. Non sono gestiti nemmeno le parti di codice, quindi il tag "pre" dovrà essere inserito a mano.
|
90
Utils/moodle-scraper/scraper.py
Normal file
90
Utils/moodle-scraper/scraper.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
# Moodle Scraper
|
||||
# 2023 - Matteo Mariotti
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from dotenv import load_dotenv
|
||||
import time
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
matricola = os.getenv('UTENTE')
|
||||
password = os.getenv('PASSWORD')
|
||||
|
||||
|
||||
url_risultati_esame = "https://elearning.uniroma1.it/mod/quiz/review.php?attempt=1096697&cmid=408285"
|
||||
codice_esame = "0721"
|
||||
|
||||
|
||||
# Main Function
|
||||
if __name__ == '__main__':
|
||||
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--start-maximized")
|
||||
options.add_argument('--log-level=3')
|
||||
|
||||
# Provide the path of chromedriver present on your system.
|
||||
driver = webdriver.Chrome(executable_path="./chromedriver.exe",
|
||||
chrome_options=options)
|
||||
driver.set_window_size(1920,1080)
|
||||
|
||||
# Loggo in elearning
|
||||
driver.get('https://elearning.uniroma1.it/auth/mtsaml/')
|
||||
time.sleep(1)
|
||||
userbox = driver.find_element(By.ID, "username")
|
||||
passbox = driver.find_element(By.ID, "password")
|
||||
userbox.send_keys(matricola)
|
||||
passbox.send_keys(password)
|
||||
button = driver.find_element(By.NAME, "_eventId_proceed")
|
||||
button.click()
|
||||
time.sleep(1)
|
||||
|
||||
#Apro i risultati del test
|
||||
driver.get(url_risultati_esame)
|
||||
|
||||
# Ottengo tutti i box delle domande
|
||||
qboxes = driver.find_elements(By.CLASS_NAME, "qtext")
|
||||
|
||||
#Prendo tutti i box delle risposte e li divido (n.b. controllare nei risultati che la divisione sia corretta)
|
||||
answers = driver.find_elements(By.CLASS_NAME, "answer")
|
||||
answers_cleaned = []
|
||||
for i, answer in enumerate(answers):
|
||||
with open("risposte.txt", "w") as f1:
|
||||
f1.write(answer.text)
|
||||
answers_cleaned.append([])
|
||||
answers_cleaned[i].append(answer.text.split("1.",1)[1].split("2.",1)[0])
|
||||
answers_cleaned[i].append(answer.text.split("1.",1)[1].split("2.",1)[1].split("3.",1)[0])
|
||||
answers_cleaned[i].append(answer.text.split("1.",1)[1].split("2.",1)[1].split("3.",1)[1])
|
||||
|
||||
# Ottenfo tutti i box delle risposte corrette e elimino la prima parte che non è necessaria
|
||||
rightAnswers = driver.find_elements(By.CLASS_NAME, "rightanswer")
|
||||
right = []
|
||||
for ranswer in rightAnswers:
|
||||
right.append(ranswer.text[24:])
|
||||
|
||||
|
||||
#Procedo alla creazione dei file
|
||||
i = 0
|
||||
for domanda, risposte, corretta in zip(qboxes, answers_cleaned, right):
|
||||
cartella = codice_esame + "_" + str(i)
|
||||
os.mkdir(cartella)
|
||||
with open(cartella + "/quest.txt", "w") as f:
|
||||
f.write(domanda.text.strip())
|
||||
j=1
|
||||
for risp in risposte:
|
||||
#Se la risposta coincide con quella corretta la metto in correct.txt altrimenti va in un file wrong{indice}.txt
|
||||
#N.B. Il controlla a volte non funziona correttamente (vengono generati solo file wrong.txt)
|
||||
if (risp.strip() == corretta.strip()):
|
||||
with open(cartella + "/correct.txt", "w") as f:
|
||||
f.write(risp.strip())
|
||||
else:
|
||||
with open(cartella + "/wrong"+str(j)+".txt", "w") as f:
|
||||
f.write(risp.strip())
|
||||
j = j+1
|
||||
i = i+1
|
||||
|
||||
time.sleep(60)
|
||||
driver.quit()
|
||||
print("Done")
|
Loading…
Add table
Add a link
Reference in a new issue