Пример #1
0
def import_(who, user):
    soup = BeautifulSoup(request.body)
    if soup.contents[0] != "NETSCAPE-Bookmark-file-1":
        abort(400, "You must send a bookmark file with the doctype " +
              " 'NETSCAPE-Bookmarks-file-1'")
    anchors = soup.find_all("a")
    bookmarks = []
    add_dates = set()
    for anchor in anchors:
        bookmark = {
            "~": int(anchor.attrs.get("add_date", conv.unixtime()))
            }
        while bookmark["~"] in add_dates:
            bookmark["~"] += 1
        add_dates.add(bookmark["~"])
        bookmark["hyperlink"] = anchor.attrs["href"]
        if bookmark["hyperlink"].startswith("place"):
            continue
        bookmark["title"] = anchor.string
        bookmark["@"] = user["email"]
        bookmark["%private"] = True
        bookmark["£created"] = conv.unixtime()
        bookmarks.append(bookmark)
    for each in bookmarks:
        conv.db().eachs.insert(each)
        del each["_id"]
        jobs.enqueue(search.IndexRecord(each), priority=1)
    response.status = 202
Пример #2
0
def add_public(who, when, user):
    if "~" not in request.json or "@" not in request.json:
        abort(400, "You must include @ and ~ with all bookmarks")
    if request.json["@"] != who or who != user["email"]:
        abort(400, "You may only add bookmarks as yourself")
    if request.json["~"] != int(when):
        abort(400, "You must use the same time in the bookmark as you post to")
    if data.has_problematic_keys(request.json):
        abort(400, "Bookmarks must not have keys prefixed with $ or £")
    request.json["£created"] = conv.unixtime()
    conv.db().bookmarks.insert(request.json)
    del request.json["_id"]
    jobs.enqueue(search.IndexRecord(request.json), priority=1)
    response.status = 202
Пример #3
0
def request_invite(who):
    # FIXME: Don't allow the pseudonym "public"
    user = whitelist(request.json, [
            "pseudonym",
            "firstName",
            "surname",
            "private_email",
            "token",
            ])
    if "private_email" not in user:
        abort(400, "You must provide a private_email field")
    user["email_key"] = str(uuid.uuid4())
    user["registered"] = c.unixtime()
    user["email"] = who
    c.db().users.ensure_index("email", unique=True)
    c.db().users.insert(user, safe=True)
    response.status = 202
    logger.info("{email} subscribed".format(email=who))
    jobs.enqueue(messages.SendInvite(user))
Пример #4
0
 def do(self):
     if _has_been_recently_billed(self.user):
         self.logger.info("Billing for {email} went through".format(
             email=self.user["email"]))
         jobs.enqueue(messages.SendInvite(self.user))
     else:
         if self.last_noted < (datetime.now() - timedelta(hours=1)):
             email = self.user["email"]
             # send some message it's all going wrong!
             self.logger.error(
                 "Billing for {email} has not happened in last hour".format(
                     email=email))
             jobs.enqueue(CheckBilling(self.user), priority=3)
         else:
             self.logger.debug(
                 "Billing for {email} has not happened".format(
                     email=email))
             jobs.enqueue(CheckBilling(
                 self.user, last_noted=self.last_noted), priority=3)
Пример #5
0
 def do(self):
     user = convenience.db().users.find_one({"email": self.email})
     user["paymill"] = _start_billing(user, self.token)
     convenience.db().users.save(user, safe=True)
     self.logger.info("Started billing " + user["email"])
     jobs.enqueue(CheckBilling(user), priority=3)