Exemplo n.º 1
0
    def post(self):
	if self.request.get('post_id') != "0":
            idea_target = Idea.get(db.Key.from_path('Idea', int(self.request.get('post_id'))))
            idea_target.idea_edit(self.request.get('content'))
	elif self.request.get('reply_id') != "0":
	    idea_target = Idea.get(db.Key.from_path('Idea', int(self.request.get('reply_id'))))
	    reply_idea = idea_create(self.request.get('content'), idea_target)
        else:
            new_idea = idea_create(self.request.get('content'), None)
        self.redirect('/')
Exemplo n.º 2
0
def list_ideas(count):
    ideas = []
    for i in range(count):
        idea = Idea()
        ideas.append(idea)

    return select_idea("Choose your idea", ideas)
Exemplo n.º 3
0
 def post(self):
     #idea_target = Idea.get_by_id(int(self.request.get('idea_id')))
     idea_target = Idea.get(db.Key.from_path('Idea', int(self.request.get('idea_id'))))
     # idea_delete(idea_target) is not work
     # idea_target.delete() is work
     idea_target.idea_delete_content()
     idea_target.put()
     self.redirect('/')
Exemplo n.º 4
0
 def from_json(self, string):
     obj = json.loads(string)
     storm = Storm()
     storm.name = obj['name']
     idea_list = obj['ideas']
     for templ in idea_list:
         storm.add_idea(Idea.from_dict(temp))
     for idea in self.ideas.values():
         if idea.parent != -1:
             parent = self.get_idea(idea.parent)
             parent.add_child(idea)
     return storm
Exemplo n.º 5
0
    def get(self):
        idea_query = Idea.all()
        idea_list = idea_query.fetch(10)
        data = json.encode(idea_list)
        idlist = "[" + "{ user_name: \"" + str(users.get_current_user()) + "\"}, "
        for i in idea_list:
            idlist += "{ id: "
            idlist += str(i.key().id()) + " }, "

        idlist = idlist.rsplit(",", 1)[0]
        idlist += "]"
        data = data.split("[", 1)[1]
        data = "[" + idlist + ", " + data
        self.response.headers['Content-Type'] = 'application/json; charset=utf-8'  
        self.response.out.write(data)
Exemplo n.º 6
0
    def get(self):
        if users.get_current_user():
            login_out_url = users.create_logout_url(self.request.uri)
        else:
            login_out_url = users.create_login_url(self.request.uri)

        idea_query = Idea.all()
        idea_list = idea_query.fetch(10)

        template_values = {
            'login_out_url': login_out_url,
            'idea_list' : idea_list,
            'user_name' : users.get_current_user(),
        }

        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 7
0
def parse_app(app, meta):
    if app['name'] == "Atom":
        return Atom(
            folder=parse_field('folder', app, meta),
            file=parse_field('file', app, meta)
        )
    elif app['name'] == "Google-chrome":
        return GoogleChrome(
            file=parse_field('file', app, meta)
        )
    elif app['name'] == "XTerm":
        return XTerm(
            command=app['cmd'],
            cwd=parse_field('cwd', app, meta),
            args=[meta[arg] for arg in app['args']]
        )
    elif app['name'] == "Slack":
        return Slack()
    elif app['name'] == "idea":
        return Idea(folder=parse_field('folder', app, meta))
Exemplo n.º 8
0
    ssc = StreamingContext(sc, batch_size)

    # Creating accumulator
    accum = sc.accumulator({}, IDAccumulatorParam())
    """ Kafka init producer and load messages from topic """

    # Producer for topic_out
    producer = KafkaProducer(bootstrap_servers=kafka_brokers_out)

    # Kafka messages are input, groupId (id8641233) has to be unique - if 2 consumers are present
    kafkaStream = KafkaUtils.createStream(ssc, zookeper_in, offset,
                                          {topic_in: 1})
    """ Mark duplicates """

    # Build key:(category, source_ip, target_ip, node_name, detect_time) !Do not change order! and value:idea
    tuples = kafkaStream.map(lambda message: Idea(message[1])). \
        map(lambda idea: ((idea.category,
                           idea.source_ip4,
                           idea.target_ip4,
                           idea.node_name,
                           idea.detect_time), idea))

    # Reduce current batch
    batch_reduced = tuples.mapValues(lambda idea: (idea.id, idea.detect_time)). \
        reduceByKey(lambda x, y: leaveOlder(x, y))

    # Apply window and leave only needed idea values (id, detect_time) then reduce
    reduced = batch_reduced.window(window_duplicate, slide_size). \
        reduceByKey(lambda x, y: leaveOlder(x, y))

    # Join reduced and raw IDEA with key, apply marking function (see def for tuple members) and filter None