Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fecth Url Question
#1
Hi all, I'm studying Python and I should write a function in Python that check whether a user has fetched some url or not through his web browser. I read about the implementation of a fetch(url) function as follows:

_cache = {}
def fetch(url):
    user = os.environ['USER']
    if user not in _cache:
        _cache[user] = {}
    if url not in _cache[user]:
        _cache[user][url] = requests.get(url).content
    return _cache[user][url]
and I'm trying to figure out how to modify this kind of function in order it checks wether a user has fetched some url or not, assuming that fetching a resource from web might take 0.1 seconds, while fetching it on the cache provides an instant result.

It should be something like:

import sys # ignore
sys.path.insert(0,'.') # ignore
from Root.fetch import fetch


def did_fetch(user, url):
    pass #REQUIRED FUNCTION THAT RETURN IF URL HAS BEEN FECTHED BY USER
with the function to be implemented inside.

Thank you very much in advance for any help! Smile
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020