Ejemplo n.º 1
0
    def comment_sync_down(self, request):
        """
			metoda koja ce vratiti sve komentare koji su dodati/menjani nakon proteglov
			vremena od poslednje sinhronizacije:
			
			Args:
				StringMessage (type): messages.Message 
				vreme poslednje sinhronizacije u %Y-%m-%dT%H:%M:%S formatu
				
			Returns:
				CommentMessageCollection (type): messages.Message 
				Izlazna poruka koja se salje klijentima
		"""

        query = CommentModel.query(CommentModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for comment in query:
            my_items.append(
                CommentMessage(
                    content=comment.content,
                    creator=comment.creator,
                    review_uuid=comment.review_uuid,
                    uuid=comment.uuid,
                    last_modified=comment.last_modified,
                )
            )

        return CommentMessageCollection(items=my_items)
Ejemplo n.º 2
0
def parse_tender(html):
    """ Parse a tender HTML and return a dictionary with information such
     as: title, description, published etc
    """
    soup = BeautifulSoup(html, 'html.parser')

    documents = find_by_class(soup, "lnkShowDocument", "a")
    description = find_by_class(soup, "ungm-list-item ungm-background", "div")
    description = description[1].text.strip().lstrip('Description')
    nodes = find_by_class(soup, "nodeName", "span")
    scraped_nodes =  [parent.find_all("span")[0].text for parent in nodes[1:]]
    with open(json_unspsc_codes, 'rb') as fp:
        codes = json.load(fp)
    unspsc_codes = [
        code['id'] for code in codes
        if code['id_ungm'] in scraped_nodes
    ]
    notice_type = find_by_class(soup, "status-tag", "span", True)
    title = find_by_class(soup, "title", "span", True)
    organization = find_by_class(soup, "highlighted", "span", True)

    reference = soup.find('span', text = re.compile('Reference:')).next_sibling.next_sibling.text
    published = soup.find('span', text = re.compile('Published on:')).next_sibling.next_sibling.text
    deadline = soup.find('span', text = re.compile('Deadline on:')).next_sibling.next_sibling.text

    tender = {
        'source': 'UNGM',
        'notice_type': notice_type,
        'title': title,
        'organization': organization,
        'reference': reference,
        'published': string_to_date(published) or date.today(),
        'deadline': string_to_datetime(deadline[:17]),
        'description': description,
        'unspsc_codes': ', '.join(unspsc_codes),
        'documents': [
            {
                'name': document.text.strip(),
                'download_url': ENDPOINT_URI + documents[0]['href']
            }
            for document in documents
        ],
    }

    gmt = deadline
    gmt = gmt[gmt.find("GMT")+4:gmt.find(")")]
    if gmt:
        tender['deadline'] -= timedelta(hours=float(gmt))
        tender['deadline'] += timedelta(hours=get_local_gmt())

    return tender
Ejemplo n.º 3
0
    def __init__(self, line):

        self.num = 0
        line, self.x = extract(line, x_re)
        line, self.priority = extract(line, pri_re)
        line, self.child_id = extract(line, c_id_re)
        line, self.repeat = extract(line, r_id_re)
        line, self.contexts = extract_all(line, c_re)
        line, self.projects = extract_all(line, p_re)
        line, self.parent_id = extract(line, p_id_re)
        line, self.added = extract(line, a_re)
        line, self.order = extract(line, o_re)
        line, dates = extract_all(line, date_re)
        self.text = line.strip()
        self.done = None
        self.due = None

        if self.added is not None:
            self.added = utils.string_to_datetime(self.added)

        dates = [utils.string_to_datetime(d) for d in dates]
        if len(dates) == 2:
            self.done, self.due = dates[0], dates[1]
        elif len(dates) == 1 and self.x is not None:
            self.done = dates[0]
        elif len(dates) == 1:
            self.due = dates[0]

        if self.order is not None:
            self.order = base62.decode(self.order)

        if self.parent_id is not None and 'c' in self.parent_id:
            self.parent_id = self.parent_id[:-1]
            self.contracted = True
        else:
            self.contracted = False
Ejemplo n.º 4
0
    def group_to_user_sync_down(self, request):
        query = GroupToUserModel.query(GroupToUserModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for group_to_user in query:
            my_items.append(
                GroupToUserMessage(
                    last_modified=group_to_user.last_modified,
                    uuid=group_to_user.uuid,
                    deleted=group_to_user.deleted,
                    group=group_to_user.group,
                    user=group_to_user.user,
                )
            )

        return GroupToUserMessageCollection(items=my_items)
Ejemplo n.º 5
0
    def group_to_review_sync_down(self, request):
        query = GroupToReviewModel.query(GroupToReviewModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for group_to_review in query:
            my_items.append(
                GroupToReviewMessage(
                    last_modified=group_to_review.last_modified,
                    uuid=group_to_review.uuid,
                    deleted=group_to_review.deleted,
                    group=group_to_review.group,
                    review=group_to_review.review,
                )
            )

        return GroupToReviewMessageCollection(items=my_items)
Ejemplo n.º 6
0
    def user_sync_down(self, request):
        query = UserModel.query(UserModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for user in query:
            my_items.append(
                UserMessage(
                    user_name=user.user_name,
                    last_modified=user.last_modified,
                    email=user.email,
                    uuid=user.uuid,
                    deleted=user.deleted,
                )
            )

        return UserMessageCollection(items=my_items)
Ejemplo n.º 7
0
    def group_sync_down(self, request):
        query = GroupModel.query(GroupModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for group in query:
            my_items.append(
                GroupMessage(
                    name=group.name,
                    owner=group.owner,
                    last_modified=group.last_modified,
                    uuid=group.uuid,
                    deleted=group.deleted,
                )
            )

        return GroupMessageCollection(items=my_items)
Ejemplo n.º 8
0
def notify_weblaunches(api_token):
    beer_bot = BeerBot(os.environ['BEER_USERNAME'], os.environ['BEER_PASSWORD'])
    telegram_bot = telegram.Bot(api_token)

    start = beer_bot.get_weblaunch_start()
    if not start:
        return

    subscriptions = model._load_weblaunch_subscriptions()

    for chat_id, latest_weblaunch_date in subscriptions.iteritems():
        if start == string_to_datetime(latest_weblaunch_date):
            continue

        send_weblaunch_notification(start, chat_id, telegram_bot)
        subscriptions[chat_id] = datetime_to_string(start)

    model.save_weblaunch_subscriptions(subscriptions)
Ejemplo n.º 9
0
    def image_sync_down(self, request):
        query = ImageModel.query(ImageModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for img in query:
            my_items.append(
                ImageMessage(
                    name=img.name,
                    image=img.image,
                    uuid=img.uuid,
                    review_uuid=img.review_uuid,
                    revobj_uuid=img.revobj_uuid,
                    is_main=img.is_main,
                    last_modified=img.last_modified,
                    deleted=img.deleted,
                )
            )

        return ImageMessageCollection(items=my_items)
Ejemplo n.º 10
0
    def revobject_sync_down(self, request):
        query = ReviewObjectModel.query(ReviewObjectModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for rev in query:
            my_items.append(
                ReviewObjectMessage(
                    name=rev.name,
                    description=rev.description,
                    creator=rev.creator,
                    lat=rev.lat,
                    lon=rev.lon,
                    tags=rev.tags,
                    last_modified=rev.last_modified,
                    uuid=rev.uuid,
                    deleted=rev.deleted,
                )
            )

        return ReviewObjectMessageCollection(items=my_items)
Ejemplo n.º 11
0
    def review_sync_down(self, request):
        query = ReviewModel.query(ReviewModel.last_modified > string_to_datetime(request.date))

        my_items = []

        for review in query:
            my_items.append(
                ReviewMessage(
                    name=review.name,
                    description=review.description,
                    rating=review.rating,
                    tags=review.tags,
                    last_modified=review.last_modified,
                    date_created=review.date_created,
                    creator=review.creator,
                    revobj_uuid=review.reviewobj_uuid,
                    uuid=review.uuid,
                    deleted=review.deleted,
                )
            )

        return ReviewMessageCollection(items=my_items)
Ejemplo n.º 12
0
Archivo: beer.py Proyecto: nip3o/beer
    def get_weblaunch_start(self):
        json = self.get_weblaunches()
        if not json:
            return None

        return string_to_datetime(json[0]['StartDate'])
Ejemplo n.º 13
0
 def test_raise_string_to_datetime(self):
     self.assertRaises(
         TypeError, string_to_datetime(self.string_now),
         type(self.string_now) != str(),
         datetime.datetime.strptime(self.string_now, self.format))
Ejemplo n.º 14
0
 def test_string_to_datetime(self):
     self.assertEqual(self.now, string_to_datetime(self.string_now))
Ejemplo n.º 15
0
 def group_to_user_delete(self, request):
     delete_model(GroupToUserModel, request.uuid, string_to_datetime(request.last_modified))
     return message_types.VoidMessage()
Ejemplo n.º 16
0
 def image_delete(self, request):
     delete_model(ImageModel, request.uuid, string_to_datetime(request.last_modified))
     return message_types.VoidMessage()
Ejemplo n.º 17
0
 def revobject_delete(self, request):
     delete_model(ReviewObjectModel, request.uuid, string_to_datetime(request.last_modified))
     return message_types.VoidMessage()
Ejemplo n.º 18
0
Archivo: hn.py Proyecto: icorecool/CHN
 def __init__(self):
     self.sort_map = dict(
         score=lambda x: x['score'],
         comment=lambda x: x['comment_cnt'],
         created=lambda x: utils.string_to_datetime(x['age']),
     )