def post(self): #global user #required = ['username','password'] #for r in required: # if r not in flask.request.form: # flask.flash("Error: {0} is required.".format(r))#nafahmidim # return flask.redirect(flask.url_for('signin')) user = flask.request.form['username'] passwd = flask.request.form['password'] if 'log in' in flask.request.form: q = """start n=node(*) return n""" lookup = Q("username", exact=str(user)) results = gdbp.nodes.filter(lookup) print len(results) for i in range(len(results)): n = gdbp.node[results[i].id] if n["password"]==passwd: flask.session['username'] = user print n.username return flask.redirect(flask.url_for('home')) flask.flash("Username doesn't exist or incorrect password") return flask.redirect(flask.url_for('signin'))
def post(self): if 'sign out' in flask.request.form: flask.session.pop('username',None) return flask.redirect(flask.url_for('main')) if 'home' in flask.request.form: return flask.redirect(flask.url_for('home')) if 'profile' in flask.request.form: flask.flash("raft tosh") print "raft tosh" return flask.redirect(flask.url_for('tanzimprofile')) if 'about us' in flask.request.form: return flask.redirect(flask.url_for('welcome')) if 'search' in flask.request.form: print "@@@@@@@@@@@" ser = flask.request.form['search'] q = """start n=node(*) return n""" lookup = Q("Id" , exact = str(ser)) result = gdbpro.nodes.filter(lookup) n=gdbpro.node[results[0].id] print n['firstname'] print n['lastname'] #print "@@@@@@@@@@@" return flask.redirect(flask.url_for('welcome')) if 'archive' in flask.request.form: print "raft writing" return flask.redirect(flask.url_for('writing'))
def post(self): if 'reset' in flask.request.form: return flask.redirect(flask.url_for('tanzimprofile')) #First=flask.request.form['firstname'] #Last=flask.request.form['lastname'] #Email=flask.request.form['email'] #Age=flask.request.form['aga'] #Country=flask.request.form['country'] #Biography=flask.request.form['biography'] user=flask.session['username'] #be nazaram oon jayi ke dare signup mishe bayad node profile khali sakhte she inja propertie hash por she . if 'send' in flask.request.form: print "**************" q = """start n=node(*) return n""" lookup = Q("Id", exact=str(user)) results = gdbpro.nodes.filter(lookup) print "###########" print len(results) for i in range(len(results)): n = gdbpro.node[results[i].id] n['firstname']=flask.request.form['firstname'] n['lastname']=flask.request.form['lastname'] n['email']=flask.request.form['email'] n['age']=flask.request.form['age'] n['country']=flask.request.form['country'] n['biography']=flask.request.form['biography'] print flask.request.form['biography'] print "'^^^^^^^^^^^^^^^^^^" return flask.redirect(flask.url_for('home'))
def get_node_by_property(self, label, property, value): labels = self.gdb.labels.get(label) lookup = Q(property, contains=value) elements = labels.filter(lookup).elements data = [dict(elt.items()) for elt in elements] return data
def test_label_filter_safe(self): n1 = self.gdb.nodes.create(key=u"válu½/ë") n1.labels.add(u"läbel") n2 = self.gdb.nodes.create(key=u"val") n2.labels.add(u"läbel") q = Q("key", "icontains", u"LU½") label = self.gdb.labels.get(u"läbel") self.assertIn(n1, label.filter(q)) self.assertNotIn(n2, label.filter(q))
def addAPKNode(db, name, sha256): # Check if APK node exist print("Checking if APK Node exist.") apk = db.labels.get("APK") filteredNode = apk.filter(Q("name", exact = name)) if len(filteredNode) == 0: createdNode = db.nodes.create(name=name,sha256=sha256) db.labels.get("APK").add(createdNode) print("Added new node: ",name) else: for i in filteredNode: createdNode = i print("APK Node existed: ", name) return createdNode
def addPermissionNode(db, name): # Check if Permission Node exist. print("Checking if Permission Node exist.") per = db.labels.get("Permission") filteredNode = per.filter(Q("name", exact = name)) if len(filteredNode) == 0: createdNode = db.nodes.create(name=name) db.labels.get("Permission").add(createdNode) print("Added new node: ",name) else: for i in filteredNode: createdNode = i print("Permission Node existed: ",name) return createdNode
def create_movie_entities(movies_label, actors_label, title, actors): title = title.title() title = multiple_replace(title, *replacements) title = re.sub(r'[0-9]*', '', title) movie_lookup = Q("name", iexact=title) movie_nodes = movies_label.filter(movie_lookup) if len(movie_nodes) > 0: movie_node = movie_nodes[0] else: movie_node = movies_label.create(name=title) # You have the Movie Node. Get or Create for actor in actors: try: actor = actor.strip() actor = multiple_replace(actor, *replacements) actor = re.sub(r'[0-9]*', '', actor) if actor: actor = unicode(actor).encode("utf-8").strip().title() actor_lookup = Q("name", iexact=actor) actor_nodes = actors_label.filter(actor_lookup) if len(actor_nodes) > 0: actor_node = actor_nodes[0] else: actor_node = actors_label.create(name=actor) actor_node.Acted_In(movie_node) print "Movie: {title} Actor: {actor}".format(title=title, actor=actor) except (UnicodeDecodeError): continue except Exception as e: print "Movie: {title} Actor: {actor}".format(title=title, actor=actor) print e continue
def post(self): y = flask.request.form['year'] m = flask.request.form['month'] da = flask.request.form['day'] user=flask.session['username'] if 'save' in flask.request.form: if (y!="" and m!="" and da!=""): d=gdbd.nodes.create(diarie=flask.request.form['table']) diaries.add(d) q = """start n=node(*) return n""" lookup = Q("username", exact=str(user)) results = gdbp.nodes.filter(lookup) #print len(results) for i in range(len(results)): #print len(results) n = gdbp.node[results[i].id] #print n.id n.relationships.create("wrote",d,year=y,month=m,day=da) #q = """start n=node(*) return n""" #q = """start n=node(*) match (n)-[:knows]-(b) return b `""" #lookup = Q("address", exact=str(user)) #results = gdb.query(q, returns=(client.Node, unicode, client.Relationship)) #results = gdb.query(q=q) #results = gdb.nodes.filter(lookup) #n = gdb.node[results[0].id] #n['diari']=flask.request.form['table'] return flask.redirect(flask.url_for('test')) else: flask.flash("you must write date!") print("you must write date!") return flask.redirect(flask.url_for('writing')) if 'log out' in flask.request.form: flask.session.pop('username',None) return flask.redirect(flask.url_for('main'))
def accio_wiki_data_format_2(): graph = GraphDatabase("http://localhost:7474/db/data/", username="******", password="******") actors_label = graph.labels.create("Actor") movies_label = graph.labels.create("Movie") base_url = "https://en.wikipedia.org/wiki/List_of_Bollywood_films_of_{year}" urls = [] for year in xrange(2008, 2013): urls.append(base_url.format(year=year)) for url in urls: print "Search URL: {url}".format(url=url) browser = mechanize.Browser() browser.set_handle_robots(False) browser.open(url) soup = BeautifulSoup(browser.response().read(), "html.parser") tables = list( soup.findAll("table", {"class": "wikitable sortable jquery-tablesorter"})) tables.extend(list(soup.findAll("table", {"class": "wikitable"}))) # All data of that url in wiki tables for table in tables: rows = table.findAll("tr") for row in rows: try: # Each Movie is a Row columns = row.findAll("td") if not columns: continue if len(columns) < 3: # Remove the Header Rows and side columns continue movie_column_index = 0 movie = columns[0].find("a") if movie is None: movie = columns[1].find("a") movie_column_index = 1 if movie is None: movie = columns[2].find("a") movie_column_index = 2 if movie is None: continue try: movie_cast = BeautifulSoup( str(columns[movie_column_index + 2]), "html.parser") except IndexError: continue title = movie.contents[0] title = multiple_replace(title, *replacements) title = unicode(title).encode("utf-8").strip().title() movie_lookup = Q("name", iexact=title) movie_nodes = movies_label.filter(movie_lookup) if len(movie_nodes) > 0: movie_node = movie_nodes[0] else: movie_node = movies_label.create(name=title) # You have the Movie Node. Get or Create actors_links = movie_cast.find_all("a") for actor_link in actors_links: if "does not exist" not in unicode( actor_link.get( "title", "does not exist")).encode("utf-8"): # if wiki page exists actor = actor_link.contents[0] actor = multiple_replace(actor, *replacements) actor = unicode(actor).encode( "utf-8").strip().title() actor_lookup = Q("name", iexact=actor) actor_nodes = actors_label.filter(actor_lookup) if len(actor_nodes) > 0: actor_node = actor_nodes[0] else: actor_node = actors_label.create(name=actor) actor_node.Acted_In(movie_node) print "Movie: {title} Actor: {actor}".format( title=title, actor=actor) except Exception: continue
def post(self): if 'reset' in flask.request.form: return flask.redirect(flask.url_for('signup')) user = flask.request.form['username'] if 'send' in flask.request.form: if (flask.request.form['username'] != "" and flask.request.form['password'] != "" and flask.request.form['a-password'] != "" and flask.request.form['mail'] != "" and flask.request.form['year'] != "" and flask.request.form['month'] != "" and flask.request.form['day'] != ""): lookup = Q("username", exact=str(user)) results = gdb.nodes.filter(lookup) if len(results) != 0: flask.flash( "your username is avilable.please change your username" ) print "your username is avilable.please change your username" return flask.redirect(flask.url_for('signup')) elif len(str(flask.request.form['password'])) <= 5: flask.flash("your password must more than 5 character") print "your password must more than 5 character" return flask.redirect(flask.url_for('signup')) elif flask.request.form['password'] != flask.request.form[ 'a-password']: flask.flash( "your password and confirm password is not equal ") print "your password and confirm password is not equal" return flask.redirect(flask.url_for('signup')) #elif (year<=0 or month<=0 or day<=0 or month>12 or day>31): # print year ,month ,day # flask.flash("your birthday's date is invalid ") # print "your birthday's date is invalid" # return flask.redirect(flask.url_for('signup')) else: flask.session['username'] = flask.request.form['username'] #msg = Message("welcom to tinder group!",sender="*****@*****.**",recipients=["*****@*****.**"]) #mail.send(msg) print "&&&&&&&&&&&&&&&&&&&" u = gdb.nodes.create( username=flask.request.form['username'], password=flask.request.form['password'], a_pssword=flask.request.form['a-password'], mail=flask.request.form['mail'], year=flask.request.form['year'], month=flask.request.form['month'], day=flask.request.form['day']) people.add(u) p = gdb.nodes.create(Id=user, firstname='-', lastname='-', age='-', gender='-', mail=flask.request.form['mail'], country='-', education='-', work='-', college='-', school='-', biography='-') lprofile.add(p) u.relationships.create("myprofile", p, Id=user) return flask.redirect(flask.url_for('home')) else: flask.flash("you must fill all the blanks!") return flask.redirect(flask.url_for('signup'))
def test_label_filter(self): n = self.gdb.nodes.create(key="value") label = n.labels.add("label") q = Q("key", "icontains", "VALUE") self.assertIn(n, label.filter(q))
def nodeExists(self, nodeKey, key='name'): search = Q(key, iexact=nodeKey) return len(self.gdb.nodes.filter(search)) > 0
def getNode(self, nodeKey, key='name'): search = Q(key, iexact=nodeKey) return self.gdb.nodes.filter(search)[0]