G
G
Greem4ik2020-07-02 22:03:37
Python
Greem4ik, 2020-07-02 22:03:37

Variable comparison?

Please tell me how to compare two variables through N time interval.
I created a new list and put a variable from the parser there. The variable in the parser changed after 2 minutes, for example, how do I compare the new variable from the parser with the one that was added to the list 2 minutes ago?

import feedparser
import time


upwork_rss_url = 'https://www.upwork.com/ab/feed/jobs/rss?sort=recency&user_location_match=1&paging=0%3B10&api_params=1&q=&securityToken=6da89e82d7da8ae885411b27044affdc3a71a8f6b7bd5867c9b62e1c7f0ce3cb7ba1097847ae92d8a180517cfb5636ced80f02cd6ca5d0327e553c48dd37da38&userUid=646985892418633728&orgUid=646985892422828033'

feeds = feedparser.parse(upwork_rss_url)
new_job = []
for a in feeds.entries:
    t = a['title']
    new_job.append(t)

if new_job[0] == feeds['entries'][0]:
    print('New job found','\n',feeds['entries'][0]['title'])

else:
    print('No new job')

I'd be happy if someone could help, thanks

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
soremix, 2020-07-02
@SoreMix

import feedparser
import time


upwork_rss_url = 'https://www.upwork.com/ab/feed/jobs/rss?sort=recency&user_location_match=1&paging=0%3B10&api_params=1&q=&securityToken=6da89e82d7da8ae885411b27044affdc3a71a8f6b7bd5867c9b62e1c7f0ce3cb7ba1097847ae92d8a180517cfb5636ced80f02cd6ca5d0327e553c48dd37da38&userUid=646985892418633728&orgUid=646985892422828033'
jobs = []

while True:

    feeds = feedparser.parse(upwork_rss_url)

    for job in feeds.entries:
        title = job['title']
        if title not in jobs:
            print('New job found\n', title)
            jobs.append(title)

    time.sleep(600)

A
Alan Gibizov, 2020-07-03
@phaggi

Despite the fact that the comrades above have already made an answer, I will also publish my creation. Let it be.

import feedparser
import time

upwork_rss_url = 'https://www.upwork.com/ab/feed/jobs/rss?sort=recency&user_location_match=1&paging=0%3B10&api_params=1&q=&securityToken=6da89e82d7da8ae885411b27044affdc3a71a8f6b7bd5867c9b62e1c7f0ce3cb7ba1097847ae92d8a180517cfb5636ced80f02cd6ca5d0327e553c48dd37da38&userUid=646985892418633728&orgUid=646985892422828033'

sleeptime = 3  # seconds
old_job = set()

while True:
    no_new_job = True
    feeds = feedparser.parse(upwork_rss_url)
    for a in feeds.entries:
        new_job = a['title']
        if new_job not in old_job:
            print('new job found:\t{}'.format(new_job))
            old_job.update([new_job])
            no_new_job = False
    if no_new_job: print('no new job...')
    time.sleep(sleeptime)

D
dmshar, 2020-07-02
@dmshar

Comparison of variables is a comparison of variables, regardless of whether you parsed it, invented it yourself, or inherited it. They are also compared in a standard way, through the use of the results of logical operators (equalities ==, greater than >, less than <, etc.). This is of course if the variables being compared are numbers. If it is data of other types, then comparison operators of these types are used. Therefore, your question sounds a bit strange.
If one variable was received earlier, and the second later - you can add them if you want and if you save them for some reason - sequentially add them to the list and then check the pair of values ​​​​from the end. If the data is obtained in general in different processes, you can write it to an external file, and extract it from there when comparing.
Do you have a parsing operation in general - outside the loop, so it's not clear where the data comes from, which "Arrives in 2 minutes"? Yes, and you clear new_job immediately after reading the data.
And in general, somehow your code does not really correspond to the above description, so you just have to guess.

G
Greem4ik, 2020-07-02
@Greem4ik

dmshar The code has not yet been fully completed, as it is stuck at this point, the cycle itself is provided.
I'll try to describe in more detail what I'm trying to do:
I pull out the title variable from the parser and there is a new_job list, this title variable is placed in it, if after 2 minutes the variable from the parser has changed, it must be compared with the new_job list in which the title variable was 2 minutes ago. That is, they (the variable from the parser and the new_job list) must differ from each other if the title variable in the parser changes.
Thank you very much for the answer
SoreMix
Thank you very much, this is what I was looking for. blessing, joy, good luck

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question