本文整理匯總了Python中werkzeug.contrib.cache.FileSystemCache.set方法的典型用法代碼示例。如果您正苦於以下問題:Python FileSystemCache.set方法的具體用法?Python FileSystemCache.set怎麽用?Python FileSystemCache.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.contrib.cache.FileSystemCache
的用法示例。
在下文中一共展示了FileSystemCache.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FileSystemSessionInterface
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class FileSystemSessionInterface(SessionInterface):
"""Uses the :class:`werkzeug.contrib.cache.FileSystemCache` as a session
backend.
:param cache_dir: the directory where session files are stored.
:param threshold: the maximum number of items the session stores before it
starts deleting some.
:param mode: the file mode wanted for the session files, default 0600
:param key_prefix: A prefix that is added to FileSystemCache store keys.
"""
session_class = FileSystemSession
def __init__(self, cache_dir, threshold, mode, key_prefix):
from werkzeug.contrib.cache import FileSystemCache
self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
self.key_prefix = key_prefix
def _generate_sid(self):
return str(uuid4())
def open_session(self, app, request):
sid = request.cookies.get(app.session_cookie_name)
if not sid:
sid = self._generate_sid()
return self.session_class(sid=sid)
data = self.cache.get(self.key_prefix + sid)
if data is not None:
return self.session_class(data, sid=sid)
return self.session_class(sid=sid)
def save_session(self, app, session, response):
domain = self.get_cookie_domain(app)
path = self.get_cookie_path(app)
if not session:
if session.modified:
self.cache.delete(self.key_prefix + session.sid)
response.delete_cookie(app.session_cookie_name,
domain=domain, path=path)
return
# Modification case. There are upsides and downsides to
# emitting a set-cookie header each request. The behavior
# is controlled by the :meth:`should_set_cookie` method
# which performs a quick check to figure out if the cookie
# should be set or not. This is controlled by the
# SESSION_REFRESH_EACH_REQUEST config flag as well as
# the permanent flag on the session itself.
# if not self.should_set_cookie(app, session):
# return
httponly = self.get_cookie_httponly(app)
secure = self.get_cookie_secure(app)
expires = self.get_expiration_time(app, session)
data = dict(session)
self.cache.set(self.key_prefix + session.sid, data,
int(app.permanent_session_lifetime.total_seconds()))
response.set_cookie(app.session_cookie_name, session.sid,
expires=expires, httponly=httponly,
domain=domain, path=path, secure=secure)
示例2: number_gen
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
def number_gen(first_part, start_num, end_num, semester, dept, subjects):
driver = webdriver.Firefox() # Firefox used for testing. Change it to PhantomJS
driver.implicitly_wait(30)
base_url = "http://result.pondiuni.edu.in/candidate.asp"
url = base_url
driver.get(base_url)
# os.mkdir(str(first_part))
os.chdir("results")
os.chdir(str(first_part))
cache = FileSystemCache('.cachedir', threshold=100000)
for number in range(start_num, end_num + 1):
current_num = "%04d" % number
numb = first_part + str(current_num)
driver.find_element_by_id("txtregno").clear()
driver.find_element_by_id("txtregno").send_keys(numb)
Select(driver.find_element_by_id("cmbdegree")).select_by_visible_text(dept)
Select(driver.find_element_by_id("cmbexamno")).select_by_visible_text(semester)
driver.find_element_by_id("button1").click()
# copying the content
page_source = cache.get(url)
page_source = driver.page_source
cache.set(url, page_source, timeout=60 * 60 * 24 * 7) # week in seconds
root = html.document_fromstring(page_source)
Cleaner(kill_tags=['noscript'], style=True)(root) # lxml >= 2.3.1
# pasting to file
filename = str(numb) + ".txt"
fp = open(filename, 'w')
fp.write((root.text_content()).encode('utf-8'))
fp.close()
driver.back()
driver.close()
return analyze(subjects)
示例3: test_filesystemcache_clear
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
def test_filesystemcache_clear():
"""
test if FileSystemCache.clear works
"""
tmp_dir = tempfile.mkdtemp()
cache = FileSystemCache(cache_dir=tmp_dir)
cache.set("foo", "bar")
cache_files = os.listdir(tmp_dir)
assert len(cache_files) == 1
cache.clear()
cache_files = os.listdir(tmp_dir)
assert len(cache_files) == 0
shutil.rmtree(tmp_dir)
示例4: test_filesystemcache_prune
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
def test_filesystemcache_prune():
"""
test if FileSystemCache._prune works and keeps the cache entry count
below the given threshold.
"""
THRESHOLD = 13
tmp_dir = tempfile.mkdtemp()
cache = FileSystemCache(cache_dir=tmp_dir, threshold=THRESHOLD)
for i in range(2 * THRESHOLD):
cache.set(str(i), i)
cache_files = os.listdir(tmp_dir)
shutil.rmtree(tmp_dir)
assert len(cache_files) <= THRESHOLD
示例5: test_filesystemcache_set_get
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
def test_filesystemcache_set_get():
"""
test if FileSystemCache.set/get works
"""
tmp_dir = tempfile.mkdtemp()
try:
cache = FileSystemCache(cache_dir=tmp_dir)
for i in range(3):
cache.set(str(i), i * i)
for i in range(3):
result = cache.get(str(i))
assert result == i * i
finally:
shutil.rmtree(tmp_dir)
示例6: BaseProvider
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class BaseProvider(object):
__metaclass__ = ABCMeta
def __init__(self, cache_dir=None, default_timeout=60 * 60 * 24,
api_key=None):
# store it in cache for 1 day. using file system cache because
# memcached is too mainstream. :)
self.cache = FileSystemCache(cache_dir=cache_dir or '/tmp/__arcoiro__',
default_timeout=default_timeout)
self._api_key = api_key
@abstractproperty
def name(self):
pass
@abstractproperty
def url(self):
pass
@abstractmethod
def get_urls_from_tag(self, tag):
pass
@property
def display_name(self):
return self.name
@property
def api_key(self):
if self._api_key is not None:
return self._api_key
config_key = '%s_API_KEY' % self.name.upper()
key = current_app.config.get(config_key)
if key is None:
raise RuntimeError('%s not defined!' % config_key)
return key
def get_cached_urls_from_tag(self, tag):
cache_key = '%s:%s' % (self.name, tag)
urls = self.cache.get(cache_key)
if urls is not None:
return urls
urls = self.get_urls_from_tag(tag)
if urls is None:
return None
self.cache.set(cache_key, urls)
return urls
示例7: parse
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
def parse(url):
cache = FileSystemCache('.cachedir', threshold=100000)
# get page
page_source = cache.get(url)
if page_source is None:
# use firefox to get page with javascript generated content
with closing(Firefox()) as browser:
browser.get(url)
page_source = browser.page_source
cache.set(url, page_source, timeout=60*60*24*7) # week in seconds
# extract text
root = html.document_fromstring(page_source)
# remove flash, images, <script>,<style>, etc
Cleaner(kill_tags=['noscript'], style=True)(root) # lxml >= 2.3.1
return root.text_content() # extract text
示例8: getSpaceInfo
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
def getSpaceInfo(spaceId):
global spaceCache
if spaceCache is None:
mkdir_p(DURACLOUD_SPACE_CACHE_DIR)
spaceCache = FileSystemCache(DURACLOUD_SPACE_CACHE_DIR, threshold=50, default_timeout=(24*3600), mode=384)
# check spaceCache, otherwise fetch info from DuraCloud
result = spaceCache.get(spaceId)
if result is None:
url = DURACLOUD_URL+ "/duradmin/download/contentItem"
auth = HTTPBasicAuth(DURACLOUD_USERNAME, DURACLOUD_PASSWORD)
payload = {'spaceId': spaceId, 'contentId': 'info.json'}
try:
response = requests.get(url, params=payload, auth=auth)
result = response.json()
spaceCache.set(spaceId, result)
except RequestException as e:
print e
raise
return result
示例9: WechatCache
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class WechatCache(object):
"""基於文件的緩存
"""
def __init__(self, cache_dir='cache', default_timeout=300):
"""初始化
cache_dir是緩存目錄
"""
self.cache = FileSystemCache(cache_dir, default_timeout=default_timeout)
def clear(self):
"""清空緩存
"""
return self.cache.clear()
def get(self, key):
"""獲取緩存
獲取鍵值key的緩存值
如果沒有對應緩存,返回None
"""
return self.cache.get(key)
def add(self, key, value, timeout=None):
"""增加緩存
如果鍵值key對應的緩存不存在,那麽增加值value到鍵值key,過期時間timeout,默認300秒
否則返回False(即不能覆蓋設置緩存)
"""
return self.cache.add(key, value, timeout)
def set(self, key, value, timeout=None):
"""設置緩存
設置鍵值key的緩存為value,過期時間300秒
"""
return self.cache.set(key, value, timeout)
def delete(self, key):
"""刪除緩存
刪除鍵值key存儲的緩存
"""
return self.cache.delete(key)
示例10: FileSystemSessionInterface
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class FileSystemSessionInterface(SessionInterface):
"""Uses the :class:`werkzeug.contrib.cache.FileSystemCache` as a session
backend.
.. versionadded:: 0.2
The `use_signer` parameter was added.
:param cache_dir: the directory where session files are stored.
:param threshold: the maximum number of items the session stores before it
starts deleting some.
:param mode: the file mode wanted for the session files, default 0600
:param key_prefix: A prefix that is added to FileSystemCache store keys.
:param use_signer: Whether to sign the session id cookie or not.
:param permanent: Whether to use permanent session or not.
"""
session_class = FileSystemSession
def __init__(self, cache_dir, threshold, mode, key_prefix,
use_signer=False, permanent=True):
from werkzeug.contrib.cache import FileSystemCache
self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
self.key_prefix = key_prefix
self.use_signer = use_signer
self.permanent = permanent
def open_session(self, app, request):
sid = request.cookies.get(app.session_cookie_name)
if not sid:
sid = self._generate_sid()
return self.session_class(sid=sid, permanent=self.permanent)
if self.use_signer:
signer = self._get_signer(app)
if signer is None:
return None
try:
sid = signer.unsign(sid)
except BadSignature:
sid = self._generate_sid()
return self.session_class(sid=sid, permanent=self.permanent)
data = self.cache.get(self.key_prefix + sid)
if data is not None:
return self.session_class(data, sid=sid)
return self.session_class(sid=sid, permanent=self.permanent)
def save_session(self, app, session, response):
domain = self.get_cookie_domain(app)
path = self.get_cookie_path(app)
if not session:
if session.modified:
self.cache.delete(self.key_prefix + session.sid)
response.delete_cookie(app.session_cookie_name,
domain=domain, path=path)
return
httponly = self.get_cookie_httponly(app)
secure = self.get_cookie_secure(app)
expires = self.get_expiration_time(app, session)
data = dict(session)
self.cache.set(self.key_prefix + session.sid, data,
total_seconds(app.permanent_session_lifetime))
if self.use_signer:
session_id = self._get_signer(app).sign(session.sid)
else:
session_id = session.sid
response.set_cookie(app.session_cookie_name, session_id,
expires=expires, httponly=httponly,
domain=domain, path=path, secure=secure)
示例11: FileSystemCache
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
from selenium.webdriver import Firefox # pip install selenium
from werkzeug.contrib.cache import FileSystemCache # pip install werkzeug
cache = FileSystemCache('.cachedir', threshold=100000)
url = sys.argv[1] if len(sys.argv) > 1 else "http://www.schibsted.cl/testqa/"
# get page
page_source = cache.get(url)
if page_source is None:
# use firefox to get page with javascript generated content
with closing(Firefox()) as browser:
browser.get(url)
page_source = browser.page_source
cache.set(url, page_source, timeout=60*60*24*7) # week in seconds
# extract text
root = html.document_fromstring(page_source)
# remove flash, images, <script>,<style>, etc
Cleaner(kill_tags=['noscript'], style=True)(root) # lxml >= 2.3.1
webtext = root.text_content() # extract text
f = open("C:/schibsted/data/Test.txt", "w");
print f
value = (webtext)
myString = str(value)
f.write(myString)
f.close()
示例12: Cache
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class Cache(object):
"""
This class is used to control the cache objects.
If TESTING is True it will use NullCache.
"""
def __init__(self, app=None):
self.cache = None
if app is not None:
self.init_app(app)
else:
self.app = None
def init_app(self, app):
"This is used to initialize cache with your app object"
app.config.setdefault('CACHE_DEFAULT_TIMEOUT', 300)
app.config.setdefault('CACHE_THRESHOLD', 500)
app.config.setdefault('CACHE_KEY_PREFIX', None)
app.config.setdefault('CACHE_MEMCACHED_SERVERS', None)
app.config.setdefault('CACHE_DIR', None)
app.config.setdefault('CACHE_TYPE', 'NullCache')
self.app = app
self._set_cache()
def _set_cache(self):
if self.app.config['TESTING']:
self.cache = NullCache()
else:
if self.app.config['CACHE_TYPE'] == 'Null':
self.cache = NullCache()
elif self.app.config['CACHE_TYPE'] == 'Simple':
self.cache = SimpleCache(
threshold=self.app.config['CACHE_THRESHOLD'],
default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'])
elif self.app.config['CACHE_TYPE'] == 'Memcached':
self.cache = MemcachedCache(
self.app.config['CACHE_MEMCACHED_SERVERS'],
default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'],
key_prefix=self.app.config['CACHE_KEY_PREFIX'])
elif self.app.config['CACHE_TYPE'] == 'GAE':
self.cache = GAEMemcachedCache(
default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'],
key_prefix=self.app.config['CACHE_KEY_PREFIX'])
elif self.app.config['CACHE_TYPE'] == 'FileSystem':
self.cache = FileSystemCache(
self.app.config['CACHE_DIR'],
threshold=self.app.config['CACHE_THRESHOLD'],
default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'])
def get(self, *args, **kwargs):
"Proxy function for internal cache object."
return self.cache.get(*args, **kwargs)
def set(self, *args, **kwargs):
"Proxy function for internal cache object."
self.cache.set(*args, **kwargs)
def add(self, *args, **kwargs):
"Proxy function for internal cache object."
self.cache.add(*args, **kwargs)
def delete(self, *args, **kwargs):
"Proxy function for internal cache object."
self.cache.delete(*args, **kwargs)
def cached(self, timeout=None, key_prefix='view/%s', unless=None):
"""
Decorator. Use this to cache a function. By default the cache key
is `view/request.path`. You are able to use this decorator with any
function by changing the `key_prefix`. If the token `%s` is located
within the `key_prefix` then it will replace that with `request.path`
Example::
# An example view function
@cache.cached(timeout=50)
def big_foo():
return big_bar_calc()
# An example misc function to cache.
@cache.cached(key_prefix='MyCachedList')
def get_list():
return [random.randrange(0, 1) for i in range(50000)]
.. code-block:: pycon
>>> my_list = get_list()
:param timeout: Default None. If set to an integer, will cache for that
amount of time.
:param key_prefix: Default 'view/%(request.path)s'. Beginning key to .
use for the cache key.
:param unless: Default None. Cache will *always* execute the caching
facilities unless this callable is true.
This will bypass the caching entirely.
#.........這裏部分代碼省略.........
示例13: Cache
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class Cache(object):
"""Base class for TimeGate caches."""
def __init__(self, path, tolerance, expiration, max_values, run_tests=True,
max_file_size=0):
"""Constructor method.
:param path: The path of the cache database file.
:param tolerance: The tolerance, in seconds to which a TimeMap is
considered young enough to be used as is.
:param expiration: How long, in seconds, the cache entries are stored
every get will be a CACHE MISS.
:param max_values: The maximum number of TimeMaps stored in cache
before some are deleted
:param run_tests: (Optional) Tests the cache at initialization.
:param max_file_size: (Optional) The maximum size (in Bytes) for a
TimeMap cache value. When max_file_size=0, there is no limit to
a cache value. When max_file_size=X > 0, the cache will not
store TimeMap that require more than X Bytes on disk.
"""
# Parameters Check
if tolerance <= 0 or expiration <= 0 or max_values <= 0:
raise CacheError("Cannot create cache: all parameters must be > 0")
self.tolerance = relativedelta(seconds=tolerance)
self.path = path.rstrip('/')
self.max_file_size = max(max_file_size, 0)
self.CHECK_SIZE = self.max_file_size > 0
self.max_values = max_values
self.backend = FileSystemCache(path,
threshold=self.max_values,
default_timeout=expiration)
# Testing cache
if run_tests:
try:
key = '1'
val = 1
self.backend.set(key, val)
assert (not self.CHECK_SIZE) or self._check_size(key) > 0
assert self.backend.get(key) == val
os.remove(self.path + '/' + md5(key).hexdigest())
except Exception as e:
raise CacheError("Error testing cache: %s" % e)
logging.debug(
"Cache created. max_files = %d. Expiration = %d. "
"max_file_size = %d" % (
self.max_values, expiration, self.max_file_size))
def get_until(self, uri_r, date):
"""Returns the TimeMap (memento,datetime)-list for the requested
Memento. The TimeMap is guaranteed to span at least until the 'date'
parameter, within the tolerance.
:param uri_r: The URI-R of the resource as a string.
:param date: The target date. It is the accept-datetime for TimeGate
requests, and the current date. The cache will return all
Mementos prior to this date (within cache.tolerance parameter)
:return: [(memento_uri_string, datetime_obj),...] list if it is
in cache and if it is within the cache tolerance for *date*,
None otherwise.
"""
# Query the backend for stored cache values to that memento
key = uri_r
try:
val = self.backend.get(key)
except Exception as e:
logging.error("Exception loading cache content: %s" % e)
return None
if val:
# There is a value in the cache
timestamp, timemap = val
logging.info("Cached value exists for %s" % uri_r)
if date > timestamp + self.tolerance:
logging.info("Cache MISS: value outdated for %s" % uri_r)
timemap = None
else:
logging.info("Cache HIT: found value for %s" % uri_r)
else:
# Cache MISS: No value
logging.info("Cache MISS: No cached value for %s" % uri_r)
timemap = None
return timemap
def get_all(self, uri_r):
"""Request the whole TimeMap for that uri.
:param uri_r: the URI-R of the resource.
:return: [(memento_uri_string, datetime_obj),...] list if it is in
cache and if it is within the cache tolerance, None otherwise.
"""
return self.get_until(uri_r, timegate_utils.now())
def refresh(self, uri_r, getter, *args, **kwargs):
"""Refreshes the cached TimeMap for a specific resource and returns it.
:param uri_r: The original resource URI to refresh the TimeMap
#.........這裏部分代碼省略.........
示例14: FileSystemSessionInterface
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
class FileSystemSessionInterface(SessionInterface):
"""Uses the :class:`werkzeug.contrib.cache.FileSystemCache` as a session
backend.
.. versionadded:: 0.2
The `use_signer` parameter was added.
:param cache_dir: the directory where session files are stored.
:param threshold: the maximum number of items the session stores before it
starts deleting some.
:param mode: the file mode wanted for the session files, default 0600
:param key_prefix: A prefix that is added to FileSystemCache store keys.
:param use_signer: Whether to sign the session id cookie or not.
"""
session_class = FileSystemSession
def __init__(self, cache_dir, threshold, mode, key_prefix,
use_signer=False):
from werkzeug.contrib.cache import FileSystemCache
self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode) #FileSystemCache是從上句導入的,threshold代表最多紀錄條數
self.key_prefix = key_prefix
self.use_signer = use_signer
def open_session(self, app, request):
sid = request.cookies.get(app.session_cookie_name)
if not sid:
sid = self._generate_sid()
return self.session_class(sid=sid)
if self.use_signer:
signer = self._get_signer(app)
if signer is None:
return None
try:
sid = signer.unsign(sid)
except BadSignature:
sid = None
data = self.cache.get(self.key_prefix + sid) #這是根據session_id獲取session值
if data is not None:
return self.session_class(data, sid=sid)
return self.session_class(sid=sid)
def save_session(self, app, session, response):
domain = self.get_cookie_domain(app)
path = self.get_cookie_path(app)
if not session: #驗證過了,就是判斷session是否為空(空字典)
if session.modified:
self.cache.delete(self.key_prefix + session.sid)
response.delete_cookie(app.session_cookie_name,
domain=domain, path=path)
return
# Modification case. There are upsides and downsides to
# emitting a set-cookie header each request. The behavior
# is controlled by the :meth:`should_set_cookie` method
# which performs a quick check to figure out if the cookie
# should be set or not. This is controlled by the
# SESSION_REFRESH_EACH_REQUEST config flag as well as
# the permanent flag on the session itself.
#if not self.should_set_cookie(app, session):
# return
httponly = self.get_cookie_httponly(app)
secure = self.get_cookie_secure(app)
expires = self.get_expiration_time(app, session)
#data = dict(session)
#self.cache.set(self.key_prefix + session.sid, data,
# int(app.permanent_session_lifetime.total_seconds()))
if self.use_signer: #簽名加密
session_id = self._get_signer(app).sign(session.sid)
else:
session_id = session.sid
response.set_cookie(app.session_cookie_name, session_id,
expires=expires, httponly=httponly,
domain=domain, path=path, secure=secure)
def save_session_without_response(self, app, session):
#httponly = self.get_cookie_httponly(app)
#secure = self.get_cookie_secure(app)
#expires = self.get_expiration_time(app, session)
data = dict(session)
self.cache.set(self.key_prefix + session.sid, data,
int(app.permanent_session_lifetime.total_seconds()))
def judge_attack(self, app, request): #判斷兩次間隔的訪問是否大於三秒
sid = request.cookies.get(app.session_cookie_name)
if not sid:
return False
current_time = time.time()
try:
last_time = self.cache.get(self.key_prefix + sid)['time'] #這是根據session_id獲取session值
except:
return False
if current_time-last_time < 3:
return True
return False
示例15: exit
# 需要導入模塊: from werkzeug.contrib.cache import FileSystemCache [as 別名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 別名]
Feedliste ist eine Datei mit einem URL zu einem ATOM-Feed pro Zeile.
Grenzwert ist die maximale Entfernung von Partyteilnehmern in Sekunden
unter der Annahme, dass die Lichtgeschwindigkeit 1 m/s beträgt.
""")
exit(1)
current_events = {}
with open(filename, 'r') as feeds:
progress = ProgressBar(maxval=len(feeds.readlines()))
with open(filename, 'r') as feeds:
for line in feeds:
feed_url = line.strip()
cached_content = feed_cache.get(feed_url)
if not cached_content:
request = get(feed_url)
events = getEvents(StringIO(request.text.encode('utf-8')))
feed_cache.set(feed_url, request.text.encode('utf-8'))
else:
events = getEvents(StringIO(cached_content))
current_events = updateEvents(current_events, events)
progress.update(progress.currval+1)
clustering = HierarchicalClustering(current_events.values(), timelikeInterval)
clusters = clustering.getlevel(threshold)
for cluster in clusters:
if len(cluster) > 2:
partyPrint(cluster, threshold)