mercredi 14 octobre 2020

Python: Finding the specific change in your string vs understanding your string has changed

I am currently using two lists, one that constantly updates and one that updates when empty (when the script starts) or when it does not equal the opposite list (the value of the two should be the same, if not, this is where I am able to sense a change in the lists value). I launch my script and pull a specific list of a web elements value, for example, "1,2,3,4,5,6,7,8,9,10" (10 values for 10 different elements) these values are supplied and appended into "list1", "list2", "list3", and "list4". The script is a big loop. When the script launches both (l22Z and l33Z) update to the same value (supplied from "list1", "list2", "list3", and "list4") because l22Z is defined before my loop as []. So initially equaling the same value, as my scraper constantly refreshes a new value can appear... l33Z will change in value as l22Z maintains the original set of values for str(res) until the end of the script (before the scraper refreshes and rescrapes) where I would send notification of a change then re-update the two lists to be the same value so we can look and notify for new changes as the scraper continues to scrape. So.... I have figured out how to sense an overall change in str(res), the problem is I want to print the specific change in my string. The changes will occur at a random point in str(res): at minute one of scraping the data set will be "1,2,3,4,5,6,7,8,9,10" though at minute 5 the data set will be "1,2,3,4,5,6,3,8,9,10" with "3" instead of "7" as the new value, how would I go about pulling and printing this specific change vs simply understanding the string has changed? Would heavily appreciate some feedback :)

l22Z = []

while True: 
    try:

       list1 = []
       list2 = []
       list5 = []
       list4 = []

       **#scrape and append values into list1, list2, list5, and list4**

       res = [i + j + s + n for i, j, s, n in zip(list1, list2, list5, list4)] 
       time.sleep(randint(1,2))

       l33Z = []
       l33Z.append(str(res))

       if l22Z == []:            
           l22Z.append(str(res))
           lin = l22Z               
           print(lin)
       
       while True:           
            try:                    
                   if l22Z != l33Z:
                       print("random message")

                       **#this is where I notify of a change before updating the lists to the same value**
                                        
                       l22Z = []
                       l22Z.append(str(res))
                   break

           #EXCEPTIONS:break

       **#refresh and rescrape for new values**

   #EXCEPTIONS:pass

Aucun commentaire:

Enregistrer un commentaire