def _make_backup(self): source_dir = os.path.join(TEST_DIR, 'test-dir') target_dir = os.path.join(TEST_DIR, 'backups') # Backup source = Source(source_dir, target_dir) source.backup()
def define_parameters(self): Source.define_parameters(self) self.w0 = daeParameter("w0", kg / s, self, "Initial water flowrate") self.a0 = daeParameter("a0", Pa, self, "Pump a coefficient 0th order") self.a1 = daeParameter("a1", Pa/(kg/s), self, "Pump a coefficient 1st order") self.a2 = daeParameter("a2", Pa/(kg**2/s**2), self, "Pump a coefficient 2nd order")
def define_parameters(self): Source.define_parameters(self) self.A = daeParameter("A", Pa / ((kg / s)**2), self, "Pump coefficient A") self.B = daeParameter("B", Pa / (kg / s), self, "Pump coefficient B") self.C = daeParameter("C", Pa, self, "Pump coefficient C")
def __init__(self, Name, Parent=None, Description=""): """ Model for the source :param Name: name of the model :param Parent: parent model :param Description: description of the model :param data: parameters and other required data """ # Instantiate the Node Source.__init__(self, Name, Parent=Parent, Description=Description)
def execute(self): source = Source(self.args['source_dir'], self.args['target_dir']) source_list = SourceList() if source in source_list: raise CommandError("such source already exists") source.backup() source_list.add(source) source_list.update() print("the source has been added successfully")
def DeclareEquations(self): """ This Method is called by the DaeTools. Here is where all the equations are defined :return: """ Source.DeclareEquations(self)
def sources(self): sources = [] for source_name in sources_metadata: source = Source(source_name, [self]) if source.posts_count > 0: sources.append(source) return sources
def post_index(): if request.form['form'] == 'Add feed': url = request.form['feed'] try: parsed = main_feed.parsing_method(url) source = main_feed.source_get(parsed) s = Source.insert_feed(url, source) if s: articles = main_feed.articles_get(parsed) Article.insert_feed(s.id, articles) except: pass return redirect('/') elif request.form['form'] == 'Set filter': filter_dir.set_filter = request.form["filter"] return redirect('/') elif request.form['form'] == 'Submit': Answer.insert_answer(request.form['answer1'], request.form['answer2'], request.form['answer3'], request.form['comment']) return redirect('/') elif request.form['form'] == 'Search': article_list, sources = search(request.form['search']) return render_template('index.html', articles=article_list, sources=sources, set_filter=filter_dir.set_filter) else: return redirect('/')
def post_sources(): feed_url = request.form['feed'] parsed = feed.parse(feed_url) feed_source = feed.get_source(parsed) source = Source.insert_from_feed(feed_url, feed_source) # feed_articles = feed.get_articles(parsed) # Article.insert_from_feed(source.id, feed_articles) return redirect('/sources')
def test_from_dict(self): reg = Source("id", "name", "fetcher", "parser", [], {}, parameters={"test": "true"}) dictionary = Source.fromDict({ "id": "id", "name": "name", "parser": "parser", "fetcher": "fetcher", "urls": [], "map": {}, "parameters": { "test": "true" } }) self.assertEqual(reg.id, dictionary.id) self.assertEqual(reg.name, dictionary.name) self.assertEqual(reg.fetcher_name, dictionary.fetcher_name) self.assertEqual(reg.urls, dictionary.urls) self.assertEqual(reg.parser_name, dictionary.parser_name) self.assertEqual(reg.parameters["test"], dictionary.get_parameter("test"))
def post(self): user = self.current_user if user: resultJSON = json.dumps({"result": False}) oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get("urlToEdit")) sourcesURLs = json.loads(self.request.get("sourcesURLs")) if self.request.get("sourcesURLs") else None sourcesNames = json.loads(self.request.get("sourcesNames")) if self.request.get("sourcesNames") else None sourcesToRemove = ( json.loads(self.request.get("sourcesToRemove")) if self.request.get("sourcesToRemove") else None ) if oldPoint == None: resultJSON = json.dumps( {"result": False, "error": "Unable to edit point. Please refresh the page and try again."} ) elif user.isLimited: resultJSON = json.dumps({"result": False, "error": "This account cannot edit points."}) else: sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key) newVersion = oldPoint.update( newTitle=self.request.get("title"), newContent=self.request.get("content"), newSummaryText=self.request.get("plainText"), user=self.current_user, imageURL=self.request.get("imageURL"), imageAuthor=self.request.get("imageAuthor"), imageDescription=self.request.get("imageDescription"), sourcesToAdd=sources, sourceKeysToRemove=sourcesToRemove, ) if newVersion: sources = newVersion.getSources() sourcesHTML = self.template_render("sources.html", {"sources": sources}) resultJSON = json.dumps( { "result": True, "version": newVersion.version, "author": newVersion.authorName, "authorURL": self.current_user.url, "dateEdited": newVersion.PSTdateEdited.strftime("%b. %d, %Y, %I:%M %p"), "pointURL": newVersion.url, "imageURL": newVersion.imageURL, "imageAuthor": newVersion.imageAuthor, "imageDescription": newVersion.imageDescription, "sourcesHTML": sourcesHTML, } ) ReportEvent.queueEventRecord(user.key.urlsafe(), newVersion.key.urlsafe(), None, "Edit Point") else: # This is the only way newVersion will fail resultJSON = json.dumps({"result": False, "error": "You appear not to be logged in."}) self.response.headers["Content-Type"] = "application/json; charset=utf-8" self.response.out.write(resultJSON)
def from_dict(cls, data): sources = [] actions = [] for source in data["sources"]: sources.append(Source.fromDict(source)) if data.get("actions"): for action in data["actions"]: actions.append(Action.from_dict(action)) return cls(sources=sources, actions=actions)
def post(self): user = self.current_user if user: resultJSON = json.dumps({'result': False}) oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit')) sourcesURLs=json.loads(self.request.get('sourcesURLs')) \ if self.request.get('sourcesURLs') else None sourcesNames=json.loads(self.request.get('sourcesNames')) \ if self.request.get('sourcesNames') else None sourcesToRemove=json.loads(self.request.get('sourcesToRemove')) \ if self.request.get('sourcesToRemove') else None if oldPoint == None: resultJSON = json.dumps({'result': False, 'error': 'Unable to edit point. Please refresh the page and try again.'}) elif user.isLimited: resultJSON = json.dumps({'result': False, 'error': 'This account cannot edit points.'}) else: sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key) newVersion = oldPoint.update( newTitle=self.request.get('title'), newContent=self.request.get('content'), newSummaryText=self.request.get('plainText'), user=self.current_user, imageURL=self.request.get('imageURL'), imageAuthor=self.request.get('imageAuthor'), imageDescription=self.request.get('imageDescription'), sourcesToAdd=sources, sourceKeysToRemove= sourcesToRemove ) if newVersion: sources = newVersion.getSources() sourcesHTML = self.template_render('sources.html', {'sources':sources}) resultJSON = json.dumps({ 'result': True, 'version': newVersion.version, 'author': newVersion.authorName, 'authorURL': self.current_user.url, 'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'), 'pointURL':newVersion.url, 'imageURL': newVersion.imageURL, 'imageAuthor': newVersion.imageAuthor, 'imageDescription': newVersion.imageDescription, 'sourcesHTML': sourcesHTML }) ReportEvent.queueEventRecord(user.key.urlsafe(), newVersion.key.urlsafe(), None, "Edit Point") else: # This is the only way newVersion will fail resultJSON = json.dumps({'result': False, 'error': 'You appear not to be logged in.'}) self.response.headers["Content-Type"] = 'application/json; charset=utf-8' self.response.out.write(resultJSON)
def get_source_list(): sources = Source.load_from_db() return jsonify({ 'sources': list( map( lambda x: { 'sourceId': x.source_id, 'name': x.name, 'description': x.description, 'url': x.url, 'languageCode': x.language_code, 'countryCode': x.country_code, }, sources)) })
def post(self): resultJSON = json.dumps({'result': False}) oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit')) sourcesURLs=json.loads(self.request.get('sourcesURLs')) \ if self.request.get('sourcesURLs') else None sourcesNames=json.loads(self.request.get('sourcesNames')) \ if self.request.get('sourcesNames') else None sourcesToRemove=json.loads(self.request.get('sourcesToRemove')) \ if self.request.get('sourcesToRemove') else None sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key) newVersion = oldPoint.update( newTitle=self.request.get('title'), newContent=self.request.get('content'), newSummaryText=self.request.get('plainText'), user=self.current_user, imageURL=self.request.get('imageURL'), imageAuthor=self.request.get('imageAuthor'), imageDescription=self.request.get('imageDescription'), sourcesToAdd=sources, sourceKeysToRemove= sourcesToRemove ) if newVersion: sources = newVersion.getSources() sourcesHTML = template.render('templates/sources.html', {'sources':sources}) resultJSON = json.dumps({ 'result': True, 'version': newVersion.version, 'author': newVersion.authorName, 'authorURL': self.current_user.url, 'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'), 'pointURL':newVersion.url, 'imageURL': newVersion.imageURL, 'imageAuthor': newVersion.imageAuthor, 'imageDescription': newVersion.imageDescription, 'sourcesHTML': sourcesHTML }) self.response.headers.add_header('content-type', 'application/json', charset='utf-8') self.response.out.write(resultJSON)
def post(self): user = self.current_user if user: resultJSON = json.dumps({'result': False}) oldPoint, oldPointRoot = Point.getCurrentByUrl( self.request.get('urlToEdit')) sourcesURLs=json.loads(self.request.get('sourcesURLs')) \ if self.request.get('sourcesURLs') else None sourcesNames=json.loads(self.request.get('sourcesNames')) \ if self.request.get('sourcesNames') else None sourcesToRemove=json.loads(self.request.get('sourcesToRemove')) \ if self.request.get('sourcesToRemove') else None if oldPoint == None: resultJSON = json.dumps({ 'result': False, 'error': 'Unable to edit point. Please refresh the page and try again.' }) elif user.isLimited: resultJSON = json.dumps({ 'result': False, 'error': 'This account cannot edit points.' }) else: sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key) newVersion = oldPoint.update( newTitle=self.request.get('title'), newContent=self.request.get('content'), newSummaryText=self.request.get('plainText'), user=self.current_user, imageURL=self.request.get('imageURL'), imageAuthor=self.request.get('imageAuthor'), imageDescription=self.request.get('imageDescription'), sourcesToAdd=sources, sourceKeysToRemove=sourcesToRemove) if newVersion: sources = newVersion.getSources() sourcesHTML = self.template_render('sources.html', {'sources': sources}) resultJSON = json.dumps({ 'result': True, 'version': newVersion.version, 'author': newVersion.authorName, 'authorURL': self.current_user.url, 'dateEdited': newVersion.PSTdateEdited.strftime( '%b. %d, %Y, %I:%M %p'), 'pointURL': newVersion.url, 'imageURL': newVersion.imageURL, 'imageAuthor': newVersion.imageAuthor, 'imageDescription': newVersion.imageDescription, 'sourcesHTML': sourcesHTML }) ReportEvent.queueEventRecord(user.key.urlsafe(), newVersion.key.urlsafe(), None, "Edit Point") else: # This is the only way newVersion will fail resultJSON = json.dumps({ 'result': False, 'error': 'You appear not to be logged in.' }) self.response.headers[ "Content-Type"] = 'application/json; charset=utf-8' self.response.out.write(resultJSON)
def sources_post(): feed_url = request.form['feed'] parsed = feed.parse(feed_url) feed_source = feed.get_source(parsed) source = Source.insert_from_feed(feed_url, feed_source) return redirect('/sources')
#! /usr/bin/env python from models.source import Source from models.content import Content import random # Main if __name__ == "__main__": source = Source() content = Content(source.url) content.save() content.push()