MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
April
Sun Mon Tue Wed Thu Fri Sat
           
11
           
2017
Months
Apr
Dec


Tue, Apr 11, 2017 8:37 pm

Writing to a CSV file with Python

I need to track the status of firewall rule requests and provide a status report every Monday. The requests are managed through a website where I can see the list of uncompleted requests and their status, but the site doesn't give me a count of the number of requests in each of the states that a request can be in, which can be "Pending Approval", "Modified", "Pending Removal" "On Hold", "Clarification Required", "Waiting Implementation", or "Waiting Removal". To obtain the count of the number of requests in each state, I download the webpage showing the requests and their status to my laptop and then run a Python script to count the queued items. But I also want to see how the numbers are changing over time, so I modified the script to write the counts to a comma-separated values (CSV) file that I can open in a spreadsheet program, such as Microsoft Excel.

To work with comma-separated value (CSV) files in a Python script, include the command import csv in the script. I also include the os.path module to use for testing whether a file already exists that will hold the data, the re module to perform regular expression parsing of lines in the downloaded webpage, the sys module for checking the command line arguments to the script, and the datetime module for determining the current date and formatting it in YYY-MM-DD format, where "YYYY" is the year, "MM" the month, and "DD" the day of the month, as explained in Python - Checking times and dates, for writing the date to the output file.

[ More Info ]

[/languages/python] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo