Ejemplo n.º 1
0
	def getLatest(self):

		# get latest entries only
		# retrieve the twitter user
		c = Config()
		twitter_user = c.getKey('twitter_user')
		
		# quit right away if no twitter user has been provided
		if twitter_user == None:
			raise Exception( 'Twitter username missing' )		

		twitter = Twitter()
		
		# retrieve the newest tweet, if any
		newest_tweet = self.getMostRecentEntry()
		if newest_tweet == None:
			# get everything
			logging.debug('no newest tweet found - requesting all')
			statuses = twitter.statuses.user_timeline(user=twitter_user,count=self.FETCH_ALL_MAX_ENTRIES)			
		else:
			# get only tweets with an id higher than the newest one
			logging.debug('requesting tweets with id greater than ' + str(newest_tweet.external_id))			
			statuses = twitter.statuses.user_timeline(user=twitter_user,since_id=newest_tweet.external_id,count=40)
			
		return(statuses)
Ejemplo n.º 2
0
	def toEntry(self, pictures):
		# and now create the entry
		c = Config()
		e = Entry(source = self.source_id,
			url = "http://picasaweb.google.com/" + c.getKey('picasa_user'))
		
		# define whether we show a matrix with pictures (in case we've got more than one) or just a bigger thumbnail)
		if(len(pictures) > 1):
			html = "<div class=\"picasa-entry\">"
			html += "<ul class=\"picasa-entry-ul\">"
			#for pic in pictures:
			#	html += self.pictureHTML(pic, True)
			html += "".join(map(lambda e: self.pictureHTML(e, True), pictures))				
			html += "</ul></div>"

			e.text = html			
			e.title = "%s new photos (%s)" % (str(len(pictures)), self._getTodayDate())
		else:
			pic = pictures.pop()
			# only one picture, we can show a bigger version of the picture
			# the markup uses different CSS classes so that we can control the styling separately
			e.title = "New photo upload (%s)" % (self._getTodayDate())
			e.text = "<div class=\"picasa-single-entry\">" + self.pictureHTML(pic, False) + "</div>"
					
		return e
Ejemplo n.º 3
0
	def getLatest(self):
		client = gdata.youtube.service.YouTubeService(client_id='Parklife', developer_key=Defaults.YOUTUBE_API_KEY)		
		gdata.alt.appengine.run_on_appengine(client)		
		
		# retrieve the favorites
		favorites = client.GetYouTubeVideoFeed( self.getFeedUri( user=Config.getKey('youtube_user'), feed='favorites', count=str(self.FETCH_ALL_MAX_ITEMS)))
		# and the uploaded
		uploaded = client.GetYouTubeVideoFeed( self.getFeedUri( user=Config.getKey('youtube_user'), feed='uploads', count=str(self.FETCH_ALL_MAX_ITEMS)))

		# merge the arrays after we've verified that all videos are valid and should be returned
		videos = filter(self.isValid, favorites.entry) + filter(self.isValid, uploaded.entry)
		
		return videos
Ejemplo n.º 4
0
def before_request_func():
    g.request_params = (
        request.args if request.method == 'GET' else request.form
    )

    # Skip pre-request actions if verifying session
    if '/session' in request.path and not valid_user_session(session):
        return

    default_config = json.load(open(app.config['DEFAULT_CONFIG'])) \
        if os.path.exists(app.config['DEFAULT_CONFIG']) else {}

    # Generate session values for user if unavailable
    if (not valid_user_session(session) and
            'cookies_disabled' not in request.args):
        session['config'] = default_config
        session['uuid'] = str(uuid.uuid4())
        session['key'] = generate_user_key()

        # Skip checking for session on any searches that don't
        # require a valid session
        if (not Endpoint.autocomplete.in_path(request.path) and
                not Endpoint.healthz.in_path(request.path)):
            return redirect(url_for(
                'session_check',
                session_id=session['uuid'],
                follow=get_request_url(request.url)), code=307)
        else:
            g.user_config = Config(**session['config'])
    elif 'cookies_disabled' not in request.args:
        # Set session as permanent
        session.permanent = True
        app.permanent_session_lifetime = timedelta(days=365)
        g.user_config = Config(**session['config'])
    else:
        # User has cookies disabled, fall back to immutable default config
        session.pop('_permanent', None)
        g.user_config = Config(**default_config)

    if not g.user_config.url:
        g.user_config.url = get_request_url(request.url_root)

    g.user_request = Request(
        request.headers.get('User-Agent'),
        get_request_url(request.url_root),
        config=g.user_config)

    g.app_location = g.user_config.url
Ejemplo n.º 5
0
def before_request_func():
    g.request_params = request.args if request.method == 'GET' else request.form
    g.cookies_disabled = False

    # Generate session values for user if unavailable
    if not valid_user_session(session):
        session['config'] = json.load(open(app.config['DEFAULT_CONFIG'])) \
            if os.path.exists(app.config['DEFAULT_CONFIG']) else {'url': request.url_root}
        session['uuid'] = str(uuid.uuid4())
        session['fernet_keys'] = generate_user_keys(True)

        # Flag cookies as possibly disabled in order to prevent against
        # unnecessary session directory expansion
        g.cookies_disabled = True

    if session['uuid'] not in app.user_elements:
        app.user_elements.update({session['uuid']: 0})

    # Always redirect to https if HTTPS_ONLY is set (otherwise default to False)
    https_only = os.getenv('HTTPS_ONLY', False)

    if https_only and request.url.startswith('http://'):
        return redirect(request.url.replace('http://', 'https://', 1),
                        code=308)

    g.user_config = Config(**session['config'])

    if not g.user_config.url:
        g.user_config.url = request.url_root.replace(
            'http://', 'https://') if https_only else request.url_root

    g.user_request = Request(request.headers.get('User-Agent'),
                             language=g.user_config.lang)
    g.app_location = g.user_config.url
Ejemplo n.º 6
0
	def getLatest(self):
		feed_link = Config.getKey( 'google_reader_feed' )
		if feed_link == None:
			raise Exception( 'Please configure your Google Reader shared items feed first!' )
			
		response = feedparser.parse( feed_link )
		return response.entries
Ejemplo n.º 7
0
def verificar_parametros():
    # Verifica se os parametros do Magento Existem e caso
    # negativo o usuario é redirecionado para a tela de
    # configurações do magento
    from app.models.config import Config
    from app.core.utils import warning
    from app.views.configuracoes.views import index

    allowed_paths = ['/logout', '/integrador/produtos/imagens/enviar']
    is_authenticated = current_user.is_active and current_user.is_authenticated
    path = request.path

    if path not in allowed_paths and is_authenticated:
        parametros = Config.by_id(1)
        if not parametros or not parametros.baseUrl:
            warning('A URL base do sistema deve ser configurada.')
            return make_response(index())

        base_url = parametros.baseUrl
        upload_url = app.config['UPLOADS_DEFAULT_URL']
        upload_url = upload_url.rsplit(
            '/', 1)[0]  # retorna somente a url base sem o /uploads

        if not base_url or upload_url is not base_url:
            upload_url = f'{base_url}/uploads'
            app.config['UPLOADS_DEFAULT_URL'] = upload_url
Ejemplo n.º 8
0
	def post(self):
		logging.debug("POST data:" + str(self.request.POST))
		form = UserSettingsForm( self.request.POST )		
		if form.is_valid():		
			# get the values from the request and save them to the database
			Config.setKeysFromDictionary(form.clean_data)
			form = UserSettingsForm(Config.getAllKeysAsDictionary())
		
			self.writeResponse( 'settings.html', { 
				'form': form.render(), 
				'message': 'Settings saved successfully'
			})
		else:
			# form not valid, must show again with the errors
			self.writeResponse( 'settings.html', { 
				'form': form,
				'message': 'There were some errors'
			})
Ejemplo n.º 9
0
 def getLatest(self):        
     most_recent = self.getMostRecentEntry()
     try:
         p = pinboard.open(Config.getKey("pinboard_user"), Config.getKey("pinboard_password"))            
         if most_recent == None:                
             posts = p.posts(count=self.FETCH_ALL_MAX_LINKS)
         else:
             posts = p.posts(date=most_recent.created.strftime("%Y-%m-%dT%H:%M:%SZ"))
     except:
         logging.error( 'Could not retrieve Pinboard posts for user: '******'pinboard_user')))
         raise
     
     # filter posts whose title is "instagram"
     if Defaults.PINBOARD_IGNORE_INSTAGRAM_LINKS == True:
         logging.debug("Filtering Instagram posts")
         posts = filter(lambda p: p['description'].lower() != 'instagram', posts)
     
     return posts
Ejemplo n.º 10
0
	def getLatest(self):
		# retrieve the user
		c = Config()
		picasa_user = c.getKey('picasa_user')		
		# quit right away if no user has been provided
		if picasa_user == None:
			raise Exception( 'Picasa username missing, unable to proceed' )
			
		# get the most recent picasa entry from the db
		latest_entry = self.getMostRecentEntry()
		if latest_entry == None:
			latest_entry_created_date = parse("2000-01-01T00:00:00")
		else:
			latest_entry_created_date = latest_entry.created
			
		# to hold the pictures to be added	
		to_add = []
			
		# get the latest pictures via the API
		client = gdata.photos.service.PhotosService()
		latest_pics = client.GetUserFeed(user=picasa_user, kind='photo', limit=self.MAX_PHOTOS) # let's see if we can process so many of them
		for pic in latest_pics.entry:
			# we don't need the time zone, and if we keep it then we'll run into trouble when comparing the dates
			picture_date = pic.published.text[0:len(pic.published.text)-5]
			logging.debug("Picasa source: latest_entry_created_date: %s - pic.published.text: %s - picture_date: %s" % (str(latest_entry_created_date), str(pic.published.text), str(picture_date)))			

			# is it newer than the newest picasa entry in the db?			
			if(parse(picture_date)) > latest_entry_created_date:
				to_add.append(pic)
			else:
				# we can probably get out of this loop
				break
				
		# create an entry only if there's something to add
		num_new_pics = len(to_add)
		
		# this should will ever only add one entry, regardless of how many pictures are found		
		logging.debug("Picasa source: new pictures to be added: " + str(num_new_pics))
		data = []
		if(num_new_pics > 0):
			data.insert(0, to_add)
								
		return(data)
Ejemplo n.º 11
0
def before_request_func():
    json_config = json.load(
        open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else {
            'url': request.url_root
        }
    g.user_config = Config(**json_config)

    if not g.user_config.url:
        g.user_config.url = request.url_root

    g.user_request = Request(request.headers.get('User-Agent'),
                             language=g.user_config.lang)
    g.app_location = g.user_config.url
Ejemplo n.º 12
0
def before_request_func():
    # Always redirect to https if HTTPS_ONLY is set (otherwise default to false)
    https_only = os.getenv('HTTPS_ONLY', False)

    if https_only and request.url.startswith('http://'):
        url = request.url.replace('http://', 'https://', 1)
        code = 308
        return redirect(url, code=code)

    json_config = json.load(open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else {'url': request.url_root}
    g.user_config = Config(**json_config)

    if not g.user_config.url:
        g.user_config.url = request.url_root.replace('http://', 'https://') if https_only else request.url_root

    g.user_request = Request(request.headers.get('User-Agent'), language=g.user_config.lang)
    g.app_location = g.user_config.url
Ejemplo n.º 13
0
def get_search_results(data):
    secret_key = generate_user_key()
    soup = Filter(user_key=secret_key, config=Config(**demo_config)).clean(
        BeautifulSoup(data, 'html.parser'))

    main_divs = soup.find('div', {'id': 'main'})
    assert len(main_divs) > 1

    result_divs = []
    for div in main_divs:
        # Result divs should only have 1 inner div
        if (len(list(div.children)) != 1 or not div.findChild()
                or 'div' not in div.findChild().name):
            continue

        result_divs.append(div)

    return result_divs
Ejemplo n.º 14
0
def load_config(config_dir: Path = None) -> Config:
    app_dir: Path = Path(__file__).parent.parent.parent
    config_dir = config_dir or app_dir / 'config'
    load_dotenv(str(config_dir / '.env'))
    log_config = load_log_config(app_dir=app_dir)
    logging_setup(config_dir, log_config)

    _bot_token = os.getenv("KARMA_BOT_TOKEN")
    with (config_dir / "bot-config.yml").open('r', encoding="utf-8") as f:
        config_file_data = yaml.load(f, Loader=yaml.FullLoader)

    return Config(
        auto_restriction=load_karmic_restriction_config(),
        db=load_db_config(app_dir),
        webhook=load_webhook_config(),
        app_dir=app_dir,
        bot_token=_bot_token,
        superusers=frozenset(config_file_data['superusers']),
        log=log_config,
        dump_chat_id=-1001459777201,  # ⚙️Testing Area >>> Python Scripts,
        tg_client=TgClientConfig(bot_token=_bot_token),
    )
Ejemplo n.º 15
0
def index():
    template = 'configuracoes/main.html'
    config = Config.by_id(1)
    form = ConfigForm()

    if config and config.baseUrl and not form.baseURL.data:
        form.configId.data = config.id
        form.baseURL.data = config.baseUrl

    if form.validate_on_submit():
        import os
        config.baseUrl = form.baseURL.data

        uploadURL = os.path.join(form.baseURL.data, 'uploads')
        current_app.config.update(UPLOADS_DEFAULT_URL=uploadURL)
        configure_uploads(current_app, (imageSet, ))

        db.session.add(config)
        db.session.commit()

        success('Registro alterado com sucesso.')

    content = {'title': 'Configurações do Sistema', 'form': form}
    return render_template(template, **content)
Ejemplo n.º 16
0
	def get(self):	
		form = UserSettingsForm(Config.getAllKeysAsDictionary())
		self.writeResponse( 'settings.html', { 'form': form.render()})
Ejemplo n.º 17
0
def load_config(app_dir: Path) -> Config:
    load_dotenv(app_dir / ".env")
    setup_logging(app_dir)
    return Config(app_dir=app_dir, )
Ejemplo n.º 18
0
def update_config_value(key):
    '''更新参数的value'''
    value = UpdateConfigValueValidator().get_data('value')
    config = Config.get_or_404(key=key)
    config.update({'value': value})
    return Success(config, error_code=1)
Ejemplo n.º 19
0
def before_request_func():
    global bang_json

    # Check for latest version if needed
    now = datetime.now()
    if now - timedelta(hours=24) > app.config['LAST_UPDATE_CHECK']:
        app.config['LAST_UPDATE_CHECK'] = now
        app.config['HAS_UPDATE'] = check_for_update(
            app.config['RELEASES_URL'],
            app.config['VERSION_NUMBER'])

    g.request_params = (
        request.args if request.method == 'GET' else request.form
    )

    # Skip pre-request actions if verifying session
    if '/session' in request.path and not valid_user_session(session):
        return

    default_config = json.load(open(app.config['DEFAULT_CONFIG'])) \
        if os.path.exists(app.config['DEFAULT_CONFIG']) else {}

    # Generate session values for user if unavailable
    if (not valid_user_session(session) and
            'cookies_disabled' not in request.args):
        session['config'] = default_config
        session['uuid'] = str(uuid.uuid4())
        session['key'] = generate_user_key()

        # Skip checking for session on any searches that don't
        # require a valid session
        if (not Endpoint.autocomplete.in_path(request.path) and
                not Endpoint.healthz.in_path(request.path) and
                not Endpoint.opensearch.in_path(request.path)):
            return redirect(url_for(
                'session_check',
                session_id=session['uuid'],
                follow=get_request_url(request.url)), code=307)
        else:
            g.user_config = Config(**session['config'])
    elif 'cookies_disabled' not in request.args:
        # Set session as permanent
        session.permanent = True
        app.permanent_session_lifetime = timedelta(days=365)
        g.user_config = Config(**session['config'])
    else:
        # User has cookies disabled, fall back to immutable default config
        session.pop('_permanent', None)
        g.user_config = Config(**default_config)

    if not g.user_config.url:
        g.user_config.url = get_request_url(request.url_root)

    g.user_request = Request(
        request.headers.get('User-Agent'),
        get_request_url(request.url_root),
        config=g.user_config)

    g.app_location = g.user_config.url

    # Attempt to reload bangs json if not generated yet
    if not bang_json and os.path.getsize(app.config['BANG_FILE']) > 4:
        try:
            bang_json = json.load(open(app.config['BANG_FILE']))
        except json.decoder.JSONDecodeError:
            # Ignore decoding error, can occur if file is still
            # being written
            pass
Ejemplo n.º 20
0
def update_config(id):
    '''更新参数配置'''
    form = UpdateConfigValidator().dt_data
    config = Config.get_or_404(id=id)
    config.update(**form)
    return Success(config, error_code=1)
Ejemplo n.º 21
0
def create_config():
    '''新建参数配置'''
    form = CreateConfigValidator().dt_data
    Config.create(**form)
    return Success(error_code=1)
Ejemplo n.º 22
0
def get_config_by_key(key):
    '''查询参数配置(基于key)'''
    config = Config.get_or_404(key=key)
    return Success(config)
Ejemplo n.º 23
0
def get_config(id):
    '''查询参数配置'''
    config = Config.get_or_404(id=id)
    return Success(config)
Ejemplo n.º 24
0
def delete_config(id):
    '''删除参数配置'''
    config = Config.get_or_404(id=id)
    config.delete()
    return Success(error_code=2)
Ejemplo n.º 25
0
def _session() -> object:
    """Return boto3 client object from Config.
    """
    _session = Config(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    return _session.create_client()
Ejemplo n.º 26
0
 def getAPI(self):
     access_token = Config.getKey( 'instagram_token' )
     if access_token == None:
         raise Exception( 'Please provide a valid Instagram access token before executing this source' )
         
     return InstagramAPI(access_token=access_token)