Home > Software design >  Best way to add and arrange lists in python
Best way to add and arrange lists in python

Time:04-21

I have 100's of url's and a list of prices that are specific to each url. I am looking for a better way to create a list where I can manually update the prices when required, I will need to see an item name and then a URL with a price that I can see all link together.

How it is currently shown does work, but looking at a mess of web url and a list of prices doesn't help me when it comes to updating the prices as I can't easily see which price refers to what URL.

What would be a convenient way to write this or process the info?

import pyautogui as pg
pg.FAILSAFE = True
from time import sleep

url = ['address-goes-here', 'different-address-goes-here', 'another-address-goes-here', 'address-goes-here', 'different-address-goes-here', 'another-address-goes-here', 'address-goes-here', 'different-address-goes-here', 'another-address-goes-here', 'address-goes-here', 'different-address-goes-here', 'another-address-goes-here']
price = ['35.69', '610.59', '99.14', '36.99', '69.59', '79.74', '35.99', '66.59', '99.14', '35.99', '60.59', '199.14']

i = 0
# enter url
while i < len(url):
    pg.tripleClick(x=4497, y=56)
    pg.typewrite(url[i])
    pg.press('enter')
    sleep(4)

    # click price and enter
    if pg.locateOnScreen('sellprice.png', confidence=0.97, region=(3375, 313, 3688, 463)):
        x, y = pg.locateCenterOnScreen('sellprice.png', confidence=0.97, region=(3375, 313, 3688, 463))
        pg.click(x, y)
        pg.write(price[i])
        print('success reg3')

        if pg.locateOnScreen('calendar.png', confidence=0.97, region=(3952, 582, 4727, 953)):
            x, y = pg.locateCenterOnScreen('calendar.png', confidence=0.97, region=(3952, 582, 4727, 953))
            pg.click(x, y)
            sleep(2)

CodePudding user response:

Since the price and data are associated with one another, you probably want to store it in some sort of data structure which shows the relationship. A simple way to do this could be a dictionary of the form

{"url1": price1, "url2": price2,...}

Or if there are also operation you want to do on the data, you could consider using a class:

class Product:
    def __init__(self, url, price):
        self.url = url
        self.price = price

products = [Product("url1", price1), Product("url2", price2), ...]
  • Related