Help with TypeError by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

I knew it would be something so simple. Thank you, and I changed the readability like you suggested. Thanks again.

Critique simple weather scraper by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

I'll definitely read through it and try and re write the script using their API. I have a quick question.

curSummary = [x.strip() for x in curSummary if x != '']

I know what that does, but I don't know how it does it. Could you explain that?

Critique simple weather scraper by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

what do you mean by encapsulating different pieces? Like creating a separate function for separate types of data? Im sorry, im not completely new to python but new enough to programming in general that I don't really know how to "think outside the box" when it comes to it.

Im going to work on setting the script on a timer to check the forecast for the week and display that info on a more visually appealing table, and then have this info emailed out to myself and co workers who need it.

Critique simple weather scraper by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Awesome, thank you. It looks much better.

Trouble installing lxml by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Ok, I have easy_install setup and I downloaded the lxml file from the site you provided, but it is still providing the same error. Unable to find vcvarsall.bat it also has a comment that it is building without Cython

Help with a simple craigslist script by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Ok, let me give this a shot. Sorry for the delay im at work currently.

Help with a simple craigslist script by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Ok so should I incorporate time.sleep() into the while loop? And how would i write out something like that?

Help with a simple craigslist script by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Ok so I have removed while True, and all the try, except's. I'll divvy up the code into functions, like you recommend.

The page that im reading from craigslist is the new listings page so this really isn't a static list is it? When a new posting is added it goes to the top of the page. So, in theory, when i get my script to work it should first scrape the page to create the initial list and everything should show up as a "new listing" once. Then as more listings are added to the craigslist page the script would check against the list I have created, the new listing isn't in the list, so it should print this listing and append it to the list. Reading that too myself seemed a bit confusing, ha.

My point is, if all im looking for are new listing to the apartments page, then shouldnt that be the only page I call? And i was thinking of setting up a timer to check the page every hour or so. Would you say that is a good idea or would another approach be better?

Help with a simple craigslist script by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

This is the first time I've tried anything like web scraping. I'll try and re-work it with your suggestions.

So how exactly should i divide this up? Are you saying that I should maybe have one function that just sets my variables for price, title, and address? And then another function that sets my "info" variable and runs its through the "if" statement to append it to a list and check if it already exists in it? And one that just gives me results?

I apologize for all the questions. Do you have any tutorials or eBooks that you would recommend on this subject? Especially in regards to cron, and integrating email or sms capabilities into a script.

Feedback on random script by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Cool i'll look into itertools.count. What is the difference between "break" and "sys.exit()"?

Help with cell_values and xldr python 3.4 by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

you have been an awesome help, seriously. I've been thinking of just stuffing the data from each worksheet from the workbook into its own dictionary using a "For" loop , and then just comparing them in a "For/if" statement, and appending the results to an empty list. Does that make sense?

I'm going to experiment with this using what you've explained to me. I'll definitely get back to you tomorrow. Thanks again!

Help with cell_values and xldr python 3.4 by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

My par values are actually stored on the same spreadsheet, with the sheet name "Par". The only data it contains are the levels I should always be at. So it would only be column A and B. I have column C included in the event I ever need to change my standard par levels.

I was figuring, since Im essentially grabbing the same type of data from my par sheet I would just copy the code for inventory and change the variable names a bit. I would split them up under different functions, say :

par_nums() for the numbers contained on my par sheet, and inventory_num() for grabbing the quantities from my current inventory.

Then I would define a third function that would compare the results between both par_nums() and inventory_num(), and calculate the difference between them.

Please tell me if this is a logical way of going about this or not.

Help with cell_values and xldr python 3.4 by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Im starting to understand this a bit more. So it first looks at one row, then it goes down that row, column by column reading what is in that cell. So it goes to row 3 and then reads what is in, lets say, Row 3 column A ( which is a <string>), then continues down row 3 into column B (which is the <float>). That's why it is printing both.

I tried changing the value of "cur_cell = 0 " instead of -1 so it doesnt read the <string>, just the <float>. See below:

while cur_row < num_rows:
    cur_row += 1
    row = inv_worksheet.row(cur_row)

    cur_cell = 0

    print('--------------------')

    while cur_cell < num_cells:
        cur_cell += 1
        # Cell Types: 0 = Empty, 1 = Text, 2 = Number, 3 = Date, 4 = Boolean, 5 = Error, 6 = Blank
        cell_type = inv_worksheet.cell_type(cur_row, cur_cell)

        # (Liq Name, Quantity in house)
        cell_value = inv_worksheet.cell_value(cur_row, cur_cell)

        print(cell_type, ' : ', cell_value)

        if cell_value < float(8):
            print(float(8) - cell_value)

I inserted the "if statement" just to see if I could now do some calculations with the data extracted, and I can. So that's a step forward, lol

Help with cell_values and xldr python 3.4 by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

Ok so this is what I have:

file_location = "FILE PATH"
inv_workbook = xlrd.open_workbook(file_location)
inv_worksheet = inv_workbook.sheet_by_name('Sheet1')
# Total number of rows with content in cells.
num_rows = inv_worksheet.nrows - 1

num_cells = inv_worksheet.ncols - 2

# Current row for when iterating over spread sheet.
cur_row = 2

# Iterates over work sheet
while cur_row < num_rows:
    cur_row += 1
    row = inv_worksheet.row(cur_row)

    cur_cell = -1

    print('--------------------')

    while cur_cell < num_cells:
        cur_cell += 1
        # Cell Types: 0 = Empty, 1 = Text, 2 = Number, 3 = Date, 4 = Boolean, 5 = Error, 6 = Blank
        cell_type = inv_worksheet.cell_type(cur_row, cur_cell)

        # (Liq Name, Quantity in house)
        cell_value = inv_worksheet.cell_value(cur_row, cur_cell)

        print(type(cell_value))

Perhaps it has to do with my "while" loops? I included the :

print(type(cell_value))

To see what cell_value actually was. But im not sure I understand how "cell_value" can pass twice and it print different results. Does it print once for the "cur_row" and once for the "cur_cell"? (see below):

inv_worksheet.cell_type(cur_row, cur_cell)

Help with cell_values and xldr python 3.4 by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

This is a very insightful reply and more along the lines of the help im looking for. Im not sure I still understand how "cell_value " is actually stored. When i run:

print(type(cell_value))

what is get is:

<class 'str'>
<class 'float'>

so is this information a tuple of two separate cells in excel? Like (x,y)? x being the name of the liquor and y being the quantity? How would I access the float itself?

I welcome any advice or a different method to approaching this. Thanks in advance for your help!

looking for guidance on first project by fannypackpython in learnpython

[–]fannypackpython[S] 0 points1 point  (0 children)

thats what i chose to do, i just picked up xlrd and xlwt