Exemple #1
0
def write(name):
    videos = video_links
    pictures = pic_links
    for url in videos:
        pid, desc, posttime, poster, video = url
        data = Context.query.filter_by(uid=name, pid=pid).first()
        if data is None:
            data = Context(uid=name,
                           pid=pid,
                           urls=video,
                           isvideo=1,
                           poster=poster,
                           posttime=posttime,
                           description=desc)
            db.session.add(data)
    for url in pictures:
        pid, desc, posttime, picture = url
        dat = Context.query.filter_by(uid=name, pid=pid).first()
        if dat is None:
            data = Context(uid=name,
                           pid=pid,
                           urls=picture,
                           isvideo=0,
                           poster=picture,
                           posttime=posttime,
                           description=desc)
            db.session.add(data)
    db.session.commit()
Exemple #2
0
def write(containerid):
    global pictures
    global videos
    for url in videos:
        pid, posttime, description, poster, video = url
        data = Context.query.filter_by(uid=containerid, pid=pid).first()
        if data is None:
            data = Context(uid=containerid,
                           pid=pid,
                           urls=video,
                           isvideo=1,
                           poster=poster,
                           posttime=posttime,
                           description=description[:500])
            db.session.add(data)
    for url in pictures:
        pid, posttime, description, picture = url
        dat = Context.query.filter_by(uid=containerid, pid=pid).first()
        if dat is None:
            data = Context(uid=containerid,
                           pid=pid,
                           urls=picture,
                           isvideo=0,
                           poster=picture,
                           posttime=posttime,
                           description=description[:500])
            db.session.add(data)
    db.session.commit()
Exemple #3
0
def write(name):
    videos = [(i[0], i[1], i[2], i[3].replace('/480', ''))
              for i in video_links]
    pictures = pic_links
    for url in videos:
        desc, posttime, poster, video = url
        data = Context.query.filter_by(id=name, urls=video).first()
        if not data:
            data = Context(id=name, urls=video, isvideo=1,
                           poster=poster, posttime=posttime, description=desc)
            db.session.add(data)
    for url in pictures:
        desc, posttime, picture = url
        dat = Context.query.filter_by(id=name, urls=picture).first()
        if not dat:
            data = Context(id=name, urls=picture, isvideo=0,
                           poster=picture, posttime=posttime, description=desc)
            db.session.add(data)
    db.session.commit()
Exemple #4
0
 def __init__(self, editmode=False):
     QtGui.QStackedWidget.__init__(self)
     self.editmode = editmode
     self._context = Context()
     form = self._setup_form()
     colors = self._setup_color_stack()
     icons = self._setup_icon_stack()
     self.addWidget(form)
     self.addWidget(colors)
     self.addWidget(icons)
Exemple #5
0
 def save_context(self):
     context = self.get_context()
     if self.editmode:
         self.window().show_status("Context updated")
         self.hide_form()
     else:
         self.window().show_status("Context created")
         self.set_default()
     context.save()
     event_register.context_change.emit()
     self._context = Context()
Exemple #6
0
def write(name):
    videos=[(i[0],i[1].replace('/480','')) for i in video_links]
    pictures=pic_links
    for url in list(set(videos)):
        poster,video=url
        data=Context.query.filter_by(id=name,urls=video).first()
        if not data:
            data=Context(name,video,1,poster)
            db.session.add(data)
        else:
            data=Context.query.filter_by(id=name,urls=video).first()
            data.poster=poster
            db.session.add(data)
    for url in list(set(pictures)):
        dat=Context.query.filter_by(id=name,urls=url).first()
        if not dat:
            data=Context(name,url,0,url)
            db.session.add(data)
        else:
            data=Context.query.filter_by(id=name,urls=url).first()
            data.poster=url
            data.urls=url
            db.session.add(data)
    db.session.commit()
Exemple #7
0
def write(name):
    videos = [(i[0], i[1].replace('/480', '')) for i in video_links]
    pictures = pic_links
    for url in list(set(videos)):
        poster, video = url
        data = Context.query.filter_by(id=name, urls=video).first()
        if not data:
            data = Context(name, video, 1, poster)
            db.session.add(data)
        else:
            data = Context.query.filter_by(id=name, urls=video).first()
            data.poster = poster
            db.session.add(data)
    for url in list(set(pictures)):
        dat = Context.query.filter_by(id=name, urls=url).first()
        if not dat:
            data = Context(name, url, 0, url)
            db.session.add(data)
        else:
            data = Context.query.filter_by(id=name, urls=url).first()
            data.poster = url
            data.urls = url
            db.session.add(data)
    db.session.commit()
Exemple #8
0
 def _init_contexts(self, contexts):
     from app.models import Context
     for row in contexts:
         context = Context(row['_id'], row['name'], row['colour'],
                           row['iconName'])
         self._buffer_context(context)
Exemple #9
0
    def parse_intent(self, messenger_id, intent):

        if Context.objects.filter(messenger_id=messenger_id).exists():
            context = Context.objects.get(messenger_id=messenger_id)

            # If bot is asking for username
            if context.context == CONST.CONTEXT_ASK_USERNAME:

                # Get account from steem
                account = self.s.get_account(intent)

                # Check if account is valid
                if account:
                    # If account is valid, save to user profile
                    fb_user = FacebookUser.objects.get(
                        messenger_id=messenger_id)
                    fb_user.steem_username = intent
                    fb_user.save()
                    self.fb_api.send_text_message(
                        messenger_id, CONST.MESSAGE_CORRECT_USERNAME)

                else:
                    # If not, send incorrect username message
                    self.fb_api.send_text_message(
                        messenger_id, CONST.MESSAGE_INCORRECT_STEEM_USERNAME)
                    # End function to not delete context
                    return

                # Delete ask username and exist function
                context.delete()
                return

            # If bot is asking for other's username
            elif context.context == CONST.CONTEXT_ASK_OTHERS_USERNAME:

                # Get account from steem
                account = self.s.get_account(intent)

                # Check if account is valid
                if account:
                    # If account is valid, save to user profile
                    self.send_others_wallet_link(messenger_id, intent)

                else:
                    # If not, send incorrect username message
                    self.fb_api.send_text_message(
                        messenger_id, CONST.MESSAGE_INCORRECT_STEEM_USERNAME)

                # Delete ask username and exist function
                context.delete()
                return

        # When user presses the Get Started button
        if intent == CONST.PAYLOAD_GET_STARTED:
            self.fb_api.send_text_message(messenger_id, CONST.MESSAGE_WELCOME)
            context = Context(messenger_id=messenger_id,
                              context=CONST.CONTEXT_ASK_USERNAME)
            context.save()

        # If View Wallet button is pressed
        elif intent == CONST.PAYLOAD_VIEW_WALLET:
            fb_user = self.get_fb_user(messenger_id)
            self.send_wallet_links(fb_user)

        # If View Other's Wallet is pressed
        elif intent == CONST.PAYLOAD_VIEW_OTHERS_WALLET:
            self.fb_api.send_text_message(messenger_id,
                                          CONST.MESSAGE_GET_OTHERS_USERNAME)
            context = Context(messenger_id=messenger_id,
                              context=CONST.CONTEXT_ASK_OTHERS_USERNAME)
            context.save()

        # If intent is not specified
        else:
            self.fb_api.send_text_message(messenger_id,
                                          CONST.MESSAGE_NO_INTENT)