CSV module - how to open a file that everyday has a different name due to date change? : this is my very first post here and I am on the beggining of my adventure with Python, sorry for any mistakes I have made. 


I am working on an automation of reporting to my collaborators. 

I am pulling the report though API with the following code : 

***code***

    import requests
    from datetime import date, timedelta
    
    today = date.today()
    yesterday = today - timedelta(days = 1)
    
    app_id = 'myappid'
    report_type = 'daily_report'
    
    params = {
      'api_token': 'api_token',
      'from': yesterday,
      'to': yesterday
    }
    
    request_url = 'https://domainxyz.com/export/{}/{}/v5'.format(app_id, report_type)
    
    res = requests.request('GET', request_url, params=params)
    
    if res.status_code != 200:
      if res.status_code == 404:
        print('There is a problem with the request URL. Make sure that it is correct')
      else:
        print('There was a problem retrieving data: ', res.text)
    else:
      f = open('{}-{}-{}-to-{}.csv'.format(app_id, report_type, params['from'], params['to']), 'w', newline='', encoding="utf-8")
      f.write(res.text)
      f.close()


and the code saves the file as 'myappid-daily_report-yesterdayDate-to-yesterdayDate.csv

and this is working just great.
Once I do have the data for yesterday, I would like to open the csv file and do some modifications with Pandas but before this, I need to open the CSV file which has kind of a dynamic name on daily basis.

I would open the file with the following 

   

     import csv
        from datetime import date, timedelta
        
        today = date.today()
        yesterday = today - timedelta(days = 1)
        
        app_id = 'myappid'
        report_type = 'daily_report'
        
        params = {
        
          'from': yesterday,
          'to': yesterday
        }
        
        
        csv_file = ('{}-{}-{}-to-{}'.format(app_id, report_type, params['from'], params['to']))
        print (csv_file)
        
        with open('csv_file' +'.csv', 'r') as csvfile:

***code***

print function returns proper name but I am getting an error which says :
Traceback (most recent call last):
  File "C:/Users/Iwan/PycharmProjects/Learning/csv_mods.py", line 20, in <module>
    with open('csv_file' +'.csv', 'r') as csvfile:
FileNotFoundError: [Errno 2] No such file or directory: 'csv_file.csv'

So I wonder how can I inject the *.csv on daily basis instead of manualy typing csv file name. 



If I have made any mistake in this post or question please point it out and I will do my best to avoid this in the future. 

Cheers,
Iwan
