Example #1
0
def unbind(permission,*args):
  """
  Unbind the permission from the given objects, if no objects given unbind the permission from all objects (delete all bindings where permission=permission)
  Returns the number of bindings that were removed or 0
  """
  count = 0
  if len(args) == 0:
    bindings = utils.fetch_all(models.PermissionBinding.all(keys_only=True).filter('permission',permission))
    count += len(bindings)
    db.delete(bindings)
  else:
    for arg in args:
      bindings = utils.fetch_all(models.PermissionBinding.all(keys_only=True).filter('permission',permission).filter('obj',arg))
      count += len(bindings)
      db.delete(bindings)
  return count
 def step2_download_html_pages(self, urls: list[str]):
     pages = utils.fetch_all(urls)
     filenames = [
         f'{self.datafolder}page{i}.html' for i in range(1,
                                                         len(pages) + 1)
     ]
     utils.write_all(filenames, pages)
Example #3
0
def delete(permission):
  """
  Delete a permission record and all of its bindings / memcache records.
  """
  bindings_keys = utils.fetch_all(models.PermissionBinding.all(keys_only=True).filter('permission',permission))
  db.delete(bindings_keys)
  # Remove permission object itself
  permission.delete()
Example #4
0
    def search_duck_duck_go(self, words):
        """
        Makes an api call to Duck Duck Go
        :param words: String or List to Strings we want to search for.
        :return:
        """
        if type(words) != list:
            words = [words]

        # Generate the url to call
        api_list = [{word: self.create_api(word)} for word in words]
        loop = asyncio.get_event_loop()  # event loop
        future = asyncio.ensure_future(fetch_all(api_list))  # tasks to do
        results = loop.run_until_complete(future)  # loop until done
        return results
from rozkladzik_api import get_public_transport_time
from utils import high_traffic_date, low_traffic_date, weekend_midday_date, fetch_all, make_failure_aware

destination = (50.0658072, 19.9500146)

data = pandas.read_pickle("/home/ppastuszka/Dokumenty/cleanedapartmentdata.pkl")

data[u'latlong'] = zip(data[u'Szerokość geograficzna'], data[u'Długosć geograficzna'])

gps_points = list(data['latlong'].unique())

# @make_failure_aware
def find_travel_time(gps_data):
    return {
        'latlong': gps_data,
        u'Czas dojazdu komunikacją w korkach': get_public_transport_time(gps_data, destination, high_traffic_date),
        u'Czas dojazdu komunikacją bez korków': get_public_transport_time(gps_data, destination, low_traffic_date),
        u'Czas dojazdu komunikacją w weekend': get_public_transport_time(gps_data, destination, weekend_midday_date),
    }

from multiprocessing import Pool
pool = Pool(30)

travel_data = pandas.DataFrame(fetch_all(gps_points, find_travel_time, pool))
data = data.merge(travel_data, on='latlong')
data = data.drop('latlong', 1)

with open("/home/ppastuszka/Dokumenty/cleanedapartmentdata2.csv", "wb") as f:
    data.to_csv(f, encoding='utf-8')

data.to_pickle("/home/ppastuszka/Dokumenty/cleanedapartmentdata2.pkl")