Exemplo n.º 1
0
def flow():
    """Route vers le lecteur d'URL pour flux rss/atom"""
    user_id = current_user.get_id()
    form = URLForm()
    if form.validate_on_submit():
        flow = Flow(url=form.url.data, user=user_id)
        flow.save()
    return render_template("flow.html", form=form)
Exemplo n.º 2
0
 def test_get_by_flow(self):
     flow_id = 1
     name = 'test_table'
     columns = [{'name': 'test', 'type': 'STRING'}]
     email = '*****@*****.**'
     in_flow = Flow.create(flow_id, name, columns, email)
     flow = Flow.get_by_flow(flow_id)
     self.assertEquals(in_flow.id, flow.id)
Exemplo n.º 3
0
 def test_get_by_flow(self):
     flow_id = 1
     name = 'test_table'
     columns = [{'name': 'test', 'type': 'STRING'}]
     email = '*****@*****.**'
     in_flow = Flow.create(flow_id, name, columns, email)
     flow = Flow.get_by_flow(flow_id)
     self.assertEquals(in_flow.id, flow.id)
Exemplo n.º 4
0
 def post_flow(self, data):
     data["obj"]["waktu"] = datetime.datetime.strptime(
         data["obj"]["waktu"], "%Y-%m-%d")
     try:
         flow = Flow.selectBy(gateID=data["obj"]["gateID"],
                              waktu=data["obj"]["waktu"])[0]
         flow.opened = data["obj"]["opened"]
         flow.timed = data["obj"]["timed"]
         flow.value = data["obj"]["value"]
         # flow autosave, karena tidak 'lazyUpdate'
     except IndexError:
         Flow(**data["obj"])
Exemplo n.º 5
0
 def __init__(self, cur_flow_list=[], json_events=[]):
     # print(rule.list)
     self.flows = []
     for json_event in json_events:
         flow = Flow.Flow()
         flow.set(json_event)
         self.flows.append(flow)
Exemplo n.º 6
0
 def deleteFlow(self, json_content):
     flow = Flow.Flow()
     flow.id = json_content["id"]
     with db_session() as db:
         # flow.delete()
         # Delete from DB
         flow.delete_db(db)
         db.commit()
     return {"response": "delete_done"}
Exemplo n.º 7
0
 def test_create(self):
     flow_id = 1
     name = 'test_table'
     columns = [{'name': 'test', 'type': 'STRING'}]
     email = '*****@*****.**'
     flow = Flow.create(flow_id, name, columns, email)
     assert flow in db.session
     self.assertEquals(flow.email, email)
     self.assertEquals(flow.flow_id, flow_id)
     self.assertEquals(eval(flow.ft_columns), [x.get('name') for x in columns])
Exemplo n.º 8
0
 def test_get_columns_from_values(self):
     values = [{
         "category": {
             "eng": "All Responses"
         },
         "node": "25cc302c-f569-4a23-8f8a-0c10732b44dc",
         "time": "2016-07-12T13:06:48.937803Z",
         "text": "asafater",
         "rule_value": "asafater",
         "value": "asafater",
         "label": "name"
     }, {
         "category": {
             "eng": "All Responses"
         },
         "node": "861ebab6-0129-4739-a609-36bb60ff0a66",
         "time": "2016-07-12T13:06:50.189755Z",
         "text": "twfggsg",
         "rule_value": "twfggsg",
         "value": "twfggsg",
         "label": "want"
     }, {
         "category": {
             "eng": "All Responses"
         },
         "node": "d7cae705-1b77-474f-8946-588f631cedbb",
         "time": "2016-07-12T13:06:52.343391Z",
         "text": "gse4twt",
         "rule_value": "gse4twt",
         "value": "gse4twt",
         "label": "reason"
     }]
     columns = Flow.get_columns_from_values(values)
     self.assertEquals(columns, [{
         'name': 'phone',
         'type': 'STRING'
     }, {
         'name': 'name (value)',
         'type': 'STRING'
     }, {
         'name': 'name (category)',
         'type': 'STRING'
     }, {
         'name': 'want (value)',
         'type': 'STRING'
     }, {
         'name': 'want (category)',
         'type': 'STRING'
     }, {
         'name': 'reason (value)',
         'type': 'STRING'
     }, {
         'name': 'reason (category)',
         'type': 'STRING'
     }])
Exemplo n.º 9
0
 def test_create(self):
     flow_id = 1
     name = 'test_table'
     columns = [{'name': 'test', 'type': 'STRING'}]
     email = '*****@*****.**'
     flow = Flow.create(flow_id, name, columns, email)
     assert flow in db.session
     self.assertEquals(flow.email, email)
     self.assertEquals(flow.flow_id, flow_id)
     self.assertEquals(eval(flow.ft_columns),
                       [x.get('name') for x in columns])
Exemplo n.º 10
0
def home():
    """Route vers la page d'accueil"""
    user_id = current_user.get_id()
    query = Flow.select(Flow.url, Flow.id).join(User).where(User.id == user_id)
    feedRSS = dict()
    feedAtom = dict()
    for flow in query:
        d = feedparser.parse(flow.url)
        if "rss" in d.version:  #Flux rss
            feedRSS[flow.url] = d
        else:  #Flux atom
            feedAtom[flow.url] = d
    return render_template("index.html", feedRSS=feedRSS, feedAtom=feedAtom)
Exemplo n.º 11
0
 def test_create_from_run(self):
     data = {'run': [u'155'], 'relayer': [u'-1'], 'text': [u'gse4twt'], 'flow': u'19', 'phone': u'+12065550100',
             'step': [u'ed49df88-404f-4e21-bc74-78c8ef6b9265'],
             'values': u'[{"category": {"eng": "All Responses"}, '
                        u'"node": "25cc302c-f569-4a23-8f8a-0c10732b44dc", "time": "2016-07-12T13:06:48.937803Z",'
                        u' "text": "asafater", "rule_value": "asafater", "value": "asafater", "label": "name"}, '
                        u'{"category": {"eng": "All Responses"}, "node": "861ebab6-0129-4739-a609-36bb60ff0a66", '
                        u'"time": "2016-07-12T13:06:50.189755Z", "text": "twfggsg", "rule_value": "twfggsg", '
                        u'"value": "twfggsg", "label": "want"}, {"category": {"eng": "All Responses"}, '
                        u'"node": "d7cae705-1b77-474f-8946-588f631cedbb", "time": "2016-07-12T13:06:52.343391Z", '
                        u'"text": "gse4twt", "rule_value": "gse4twt", "value": "gse4twt", "label": "reason"}]',
             'time': [u'2016-07-12T13:06:52.387647Z'], 'steps': [u'[{"node": "19af6b8c-d5d3-43f8-b1f8-7e2728d9cac7",'
                                                                 u' "arrived_on": "2016-07-12T13:06:46.593063Z", '
                                                                 u'"left_on": "2016-07-12T13:06:46.608539Z", '
                                                                 u'"text": "What is your name", "type": "A", '
                                                                 u'"value": null}, '
                                                                 u'{"node": "25cc302c-f569-4a23-8f8a-0c10732b44dc",'
                                                                 u' "arrived_on": "2016-07-12T13:06:46.608539Z", '
                                                                 u'"left_on": "2016-07-12T13:06:48.937803Z", '
                                                                 u'"text": "asafater", "type": "R",'
                                                                 u' "value": "asafater"}, '
                                                                 u'{"node": "b01e1930-880e-4546-833d-0bf3a7f14cf9", '
                                                                 u'"arrived_on": "2016-07-12T13:06:48.938735Z",'
                                                                 u' "left_on": "2016-07-12T13:06:49.016967Z",'
                                                                 u' "text": "What do you want?", "type": "A",'
                                                                 u' "value": null}, '
                                                                 u'{"node": "861ebab6-0129-4739-a609-36bb60ff0a66",'
                                                                 u' "arrived_on": "2016-07-12T13:06:49.016967Z",'
                                                                 u' "left_on": "2016-07-12T13:06:50.189755Z",'
                                                                 u' "text": "twfggsg", "type": "R",'
                                                                 u' "value": "twfggsg"},'
                                                                 u' {"node": "62e516d2-4e03-45c4-a02b-5d89f0e17254",'
                                                                 u' "arrived_on": "2016-07-12T13:06:50.190754Z",'
                                                                 u' "left_on": "2016-07-12T13:06:50.258417Z",'
                                                                 u' "text": "Why", "type": "A", "value": null},'
                                                                 u' {"node": "d7cae705-1b77-474f-8946-588f631cedbb",'
                                                                 u' "arrived_on": "2016-07-12T13:06:50.258417Z",'
                                                                 u' "left_on": "2016-07-12T13:06:52.343391Z",'
                                                                 u' "text": "gse4twt", "type": "R",'
                                                                 u' "value": "gse4twt"},'
                                                                 u' {"node": "ed49df88-404f-4e21-bc74-78c8ef6b9265",'
                                                                 u' "arrived_on": "2016-07-12T13:06:52.344270Z",'
                                                                 u' "left_on": null, "text": null, "type": "A",'
                                                                 u' "value": null}]'],
             'channel': [u'-1']}
     email = '*****@*****.**'
     flow = Flow.create_from_run(data, email)
     assert flow in db.session
     self.assertEquals(unicode(flow.flow_id), data.get('flow'))
Exemplo n.º 12
0
    def init_DB(self):

        # if connection_string.startswith('sqlite'):
        #     db_file = re.sub("sqlite.*:///", "", connection_string)
        #     os.makedirs(os.path.dirname(db_file))

        # 3 commands for creating database

        base = Base.Base()
        Flow.Flow()

        engine = assert_database_type()
        base.metadata.create_all(engine)

        response = "OK"
        return response
Exemplo n.º 13
0
def save_run():
    action = 'insert'
    data = request.json or request.form
    phone = data.get('phone')
    flow_id = data.get('flow')
    email = request.args.get('email')
    base_language = data.get('flow_base_language')
    values = json.loads(data.get('values'))

    flow = Flow.get_by_flow(flow_id)
    if flow:
        update_fusion_table.delay(flow.id, phone, values, email, base_language)
    else:
        action = 'create and insert'
        create_flow_and_update_ft.delay(data, email, phone, values, base_language)

    response = {'action': action}
    return create_response(response)
Exemplo n.º 14
0
def save_run():
    action = 'insert'
    data = request.json or request.form
    phone = data.get('phone')
    flow_id = data.get('flow')
    email = request.args.get('email')
    base_language = data.get('flow_base_language')
    values = json.loads(data.get('values'))

    flow = Flow.get_by_flow(flow_id)
    if flow:
        update_fusion_table.delay(flow.id, phone, values, email, base_language)
    else:
        action = 'create and insert'
        create_flow_and_update_ft.delay(data, email, phone, values,
                                        base_language)

    response = {'action': action}
    return create_response(response)
Exemplo n.º 15
0
 def test_get_columns_from_values(self):
     values = [{"category": {"eng": "All Responses"}, "node": "25cc302c-f569-4a23-8f8a-0c10732b44dc",
                "time": "2016-07-12T13:06:48.937803Z", "text": "asafater", "rule_value": "asafater",
                "value": "asafater", "label": "name"}, {"category": {"eng": "All Responses"},
                                                        "node": "861ebab6-0129-4739-a609-36bb60ff0a66",
                                                        "time": "2016-07-12T13:06:50.189755Z",
                                                        "text": "twfggsg", "rule_value": "twfggsg",
                                                        "value": "twfggsg", "label": "want"},
               {"category": {"eng": "All Responses"},
                "node": "d7cae705-1b77-474f-8946-588f631cedbb", "time": "2016-07-12T13:06:52.343391Z",
                "text": "gse4twt", "rule_value": "gse4twt", "value": "gse4twt", "label": "reason"}]
     columns = Flow.get_columns_from_values(values)
     self.assertEquals(columns, [{'name': 'phone', 'type': 'STRING'},
                                 {'name': 'name (value)', 'type': 'STRING'},
                                 {'name': 'name (category)', 'type': 'STRING'},
                                 {'name': 'want (value)', 'type': 'STRING'},
                                 {'name': 'want (category)', 'type': 'STRING'},
                                 {'name': 'reason (value)', 'type': 'STRING'},
                                 {'name': 'reason (category)', 'type': 'STRING'}
                                 ])
Exemplo n.º 16
0
#!/usr/bin/env python
# coding:utf-8
import redis
from torndb import Connection

from models import Domain, Flow, Rule
import settings

rd = redis.Redis(settings.REDIS_HOST, settings.REDIS_PORT)
db = Connection("127.0.0.1", "spider", user="******", password="******")

domains = db.query("select * from domain")

for d in domains:
    domain = Domain(rd, d["domain"])
    domain.update(d)
    if "scheduled" not in domain:
        domain["scheduled"] = 0

    rule_datas = db.query("select * from rule where domain = %s", d["domain"])
    for rule_data in rule_datas:
        rule = Rule(rd, d["domain"])
        rule.update(rule_data)

    flows = db.query("select * from flow where domain = %s", d["domain"])
    for f in flows:
        flow = Flow(rd, f["flow"])
        flow.update(f)
        if "scheduled" not in flow:
            flow["scheduled"] = 0
Exemplo n.º 17
0
from neo4jrestclient import GraphDatabase
from models import Flow, Question, Answer

flows = [
    Flow(
        'morrowind', "Morrowind-style",
        "A fantasy character creation process like the one at the start of the game Morrowind."
    )
]


def morrowind_flow(start_node):
    flow_id = 'morrowind'
    question_index = db.nodes.indexes.get('questions')

    q1 = Question(id='q1',
                  text='What surrounded you when you were young?',
                  answers=[
                      Answer(id='q1a1',
                             text='The sea',
                             reward_type='Background',
                             reward_value='Coastal',
                             next='q4'),
                      Answer(id='q1a2',
                             text='Fields',
                             reward_type='Background',
                             reward_value='Rural',
                             next='q2'),
                      Answer(id='q1a3',
                             text='Buildings',
                             reward_type='Background',
Exemplo n.º 18
0
 def get_all_flows(self):
     '''get all flow ids'''
     return Flow.filter(self.rd)
Exemplo n.º 19
0
 def getFlow(self, json_content):
     flow = Flow.Flow()
     if json_content is not None and bool(json_content) is True:
         flow.set(json_content)
     response = flow.get_by_filter()
     return response
Exemplo n.º 20
0
 def get_flows(self, **condition):
     """all flows under this domain
     """
     flows = Flow.filter(self.rd, domain=self.domain.name,
                         priority=self.prio, **condition)
     return flows
Exemplo n.º 21
0
 def get_prios(self):
     '''
     Get all priorities for a given domain.
     '''
     sf = Flow.filter(self.rd, domain=self.domain.name)
     return sorted(set(s['priority'] for s in sf))
Exemplo n.º 22
0
 def test_create_from_run(self):
     data = {
         'run': [u'155'],
         'relayer': [u'-1'],
         'text': [u'gse4twt'],
         'flow':
         u'19',
         'phone':
         u'+12065550100',
         'step': [u'ed49df88-404f-4e21-bc74-78c8ef6b9265'],
         'values':
         u'[{"category": {"eng": "All Responses"}, '
         u'"node": "25cc302c-f569-4a23-8f8a-0c10732b44dc", "time": "2016-07-12T13:06:48.937803Z",'
         u' "text": "asafater", "rule_value": "asafater", "value": "asafater", "label": "name"}, '
         u'{"category": {"eng": "All Responses"}, "node": "861ebab6-0129-4739-a609-36bb60ff0a66", '
         u'"time": "2016-07-12T13:06:50.189755Z", "text": "twfggsg", "rule_value": "twfggsg", '
         u'"value": "twfggsg", "label": "want"}, {"category": {"eng": "All Responses"}, '
         u'"node": "d7cae705-1b77-474f-8946-588f631cedbb", "time": "2016-07-12T13:06:52.343391Z", '
         u'"text": "gse4twt", "rule_value": "gse4twt", "value": "gse4twt", "label": "reason"}]',
         'time': [u'2016-07-12T13:06:52.387647Z'],
         'steps': [
             u'[{"node": "19af6b8c-d5d3-43f8-b1f8-7e2728d9cac7",'
             u' "arrived_on": "2016-07-12T13:06:46.593063Z", '
             u'"left_on": "2016-07-12T13:06:46.608539Z", '
             u'"text": "What is your name", "type": "A", '
             u'"value": null}, '
             u'{"node": "25cc302c-f569-4a23-8f8a-0c10732b44dc",'
             u' "arrived_on": "2016-07-12T13:06:46.608539Z", '
             u'"left_on": "2016-07-12T13:06:48.937803Z", '
             u'"text": "asafater", "type": "R",'
             u' "value": "asafater"}, '
             u'{"node": "b01e1930-880e-4546-833d-0bf3a7f14cf9", '
             u'"arrived_on": "2016-07-12T13:06:48.938735Z",'
             u' "left_on": "2016-07-12T13:06:49.016967Z",'
             u' "text": "What do you want?", "type": "A",'
             u' "value": null}, '
             u'{"node": "861ebab6-0129-4739-a609-36bb60ff0a66",'
             u' "arrived_on": "2016-07-12T13:06:49.016967Z",'
             u' "left_on": "2016-07-12T13:06:50.189755Z",'
             u' "text": "twfggsg", "type": "R",'
             u' "value": "twfggsg"},'
             u' {"node": "62e516d2-4e03-45c4-a02b-5d89f0e17254",'
             u' "arrived_on": "2016-07-12T13:06:50.190754Z",'
             u' "left_on": "2016-07-12T13:06:50.258417Z",'
             u' "text": "Why", "type": "A", "value": null},'
             u' {"node": "d7cae705-1b77-474f-8946-588f631cedbb",'
             u' "arrived_on": "2016-07-12T13:06:50.258417Z",'
             u' "left_on": "2016-07-12T13:06:52.343391Z",'
             u' "text": "gse4twt", "type": "R",'
             u' "value": "gse4twt"},'
             u' {"node": "ed49df88-404f-4e21-bc74-78c8ef6b9265",'
             u' "arrived_on": "2016-07-12T13:06:52.344270Z",'
             u' "left_on": null, "text": null, "type": "A",'
             u' "value": null}]'
         ],
         'channel': [u'-1']
     }
     email = '*****@*****.**'
     flow = Flow.create_from_run(data, email)
     assert flow in db.session
     self.assertEquals(unicode(flow.flow_id), data.get('flow'))
Exemplo n.º 23
0
def create_flow_and_update_ft(data, email, phone, values, base_language):
    flow = Flow.create_from_run(data, email)
    flow.update_fusion_table(phone, values, base_language)