0

This code accepts BTC, ICX,..... inputs one at a time and i would to make accept multiple inputs and output multiple files with the same name as the input. How can i do it?

eg. ETH,ICX, ALG...

Edit: i would like to give n currencies.

from cryptocmd import CmcScraper

currency = input("enter currency:")
date_from = input("enter begining date")
date_to = input ("enter end date")

# initialise scraper with time interval

if date_from and date_to:
    scraper = CmcScraper(currency, date_from, date_to)
else:
    scraper = CmcScraper(currency)

# get raw data as list of list
headers, data = scraper.get_data()

# get data in a json format
json_data = scraper.get_data("json")

# export the data to csv
scraper.export("csv")

# get dataframe for the data
df = scraper.get_dataframe()
4
  • Do you want to perform this input/output loop "n" times until you want to exit, or do you want to give "n" currencies etc. and perform the script for each of inputs? Commented Nov 18, 2021 at 11:31
  • What you can do is put your entire code in a while loop as: while(True): ... if currency=="": break and break the loop if currency is empty Commented Nov 18, 2021 at 11:34
  • @bhagyesh-dudhediya for example if date_from and date_to: ................................... df = scraper.get_dataframe() if currency=="": break ...... Dont i have to use a split function coz of the N inputs? Commented Nov 18, 2021 at 11:48
  • @Tzane Yes, "n" currencies Commented Nov 18, 2021 at 11:49

1 Answer 1

1

If you want to give multiple values in a single input, you can use split to separate each input and use a for loop to iterate over each one:

currency_n = input("enter currency:")
date_from = input("enter begining date")
date_to = input ("enter end date")

for currency in currency_n.split(" "):
    # initialise scraper with time interval

    if date_from and date_to:
        scraper = CmcScraper(currency, date_from, date_to)
    else:
        scraper = CmcScraper(currency)

    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.