r/pythonhelp • • Oct 12 '21

Unable to get past first bit of Jeopardy! parser

Hello,

Relatively new to programming in general and very new to Python. I've been working with this Jeopardy parser to parse a bunch of html files into CSVs. I want to make my own Jeopardy clue database for both Python/DB practice as well as Jeopardy practice. It's a win-win!

Prior to this, I was able to use the download script to successfully download ~8000 html files. I have them stored in a folder called "j-archive archive" which is what the parser script is referencing.

However, when I run the parser, all it does is print "Using 8 threads" and then brings up a new command line, and nothing seems to happen in my folders - no CSVs, no nothing. Seems like it just stopping here. How can I move forward? I have tried a few things and was able to move past this point to some extent, but then it tells me that 'main' isn't defined.

from __future__ import print_function
from bs4 import BeautifulSoup
import time
import lxml
import sys
import os
import re
import csv
import progressbar
import concurrent.futures as futures

# Break up CSVs into seasons

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
SITE_FOLDER = os.path.join(CURRENT_DIR, "j-archive archive")
SAVE_FOLDER = os.path.join(CURRENT_DIR, "j-archive-csv")
NUM_THREADS = 2
try:
	import multiprocessing
	NUM_THREADS = multiprocessing.cpu_count() * 2
	print('Using {} threads'.format(NUM_THREADS))
except (ImportError, NotImplementedError):
	pass

For more context, I believe this was written in Python 2 but I'm running 3.

I really appreciate any help. Happy to provide more details.

2 Upvotes

10 comments sorted by

1

u/skellious Oct 12 '21

EDIT: never mind I realised you are trying to adapt someone else's code but only posted a tiny snippet of it here for some reason.

why is your code using a try-except block? You generally want to know if those things are having errors.

As for what is going wrong, at the moment all you are doing is importing a bunch of libraries, setting some variables, setting NUM_THREADS AGAIN for some reason and then printing how many threads you are using.

Your program isn't actually DOING anything, because you haven't TOLD IT TO DO ANYTHING.

1

u/RealDominiqueWilkins Oct 12 '21

That isn’t all of the code. I linked to it on the OP.

1

u/skellious Oct 12 '21

yeah I got that sorry it was confusing.

Can you clarify if you wrote the code or just adapted it?

1

u/RealDominiqueWilkins Oct 12 '21

I just adapted it. The entirety of the code just seems to stop after the num_threads print and nothing happens. It just says “using 8 threads” and gives me another command line prompt.

1

u/skellious Oct 12 '21

I just tried running the downloader and its creating empty season files but not filling them with any data. do you have data in them?

1

u/RealDominiqueWilkins Oct 12 '21

Yeah I ended up with like 8000 html files. The download script worked great. I don’t think I even altered it at all.

1

u/skellious Oct 12 '21

interesting. for me it does nothing. what version of python are you using? I'm on 3.9.2

2

u/RealDominiqueWilkins Oct 12 '21

I’ve left home, so I’m not sure. I do recall having to make sure I pip installed beautiful soup 4.

1

u/skellious Oct 12 '21

well, i've found MY first problem. episodelinks in downloads in not populating. its just returning an empty list. thats why nothing is being written to file.

I'm too tired to puzzle it out right now but if its still an issue next time I have free time ill look at it more

1

u/skellious Oct 12 '21

could you try adding some print commands into the various parts of the code? (so, print the season name when starting to process each season and the episode name when starting to process each episode)

that should give you some insight into what is going on.

then put print statements to print the parsed output of each episode as well.

if you're not seeing the expected output, then you know where to start troubleshooting.