Beispiel #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import Flask, request, redirect, url_for, jsonify
from config import Config, make_celery


app = Flask(__name__)
app.config.from_object(Config)

celery_app = make_celery(app)


@celery_app.task(name='app.test_celery')
def test_celery():
    print 'hello, world'

@celery_app.task(name='app.math_add')
def add_task(a, b):
    print a+b



@app.route('/')
def index():
    return 'hello, world'

@app.route('/tasks/test-celery/')
def test_celery_run():
    test_celery.delay()
    return 'checkout shell to get test result'
Beispiel #2
0
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from config import Config, make_celery
import os

basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config.from_object(Config)

db = SQLAlchemy(app)
db.init_app(app)
migrate = Migrate(app, db)

celery = make_celery(app)
celery.conf.update(app.config)

login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)

from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)

from .main import main as main_blueprint
app.register_blueprint(main_blueprint)

from .api import api_routes as api_blueprint
app.register_blueprint(api_blueprint)
Beispiel #3
0
from flask import Flask

from config import make_celery, Configuration

from flask_sqlalchemy import SQLAlchemy

### Flask###

app = Flask(__name__)
app.config.from_object(Configuration)
db = SQLAlchemy(app)

### Celery ###

client = make_celery(app)
client.conf.update(app.config)

### Blueprints ###

from views import *

app.register_blueprint(general, url_prefix="/")
app.register_blueprint(news, url_prefix="/news")

from views.parsers import run
Beispiel #4
0
import re
import urllib
from config import make_celery, app
from celery import Task

celery = make_celery(app)

@celery.task(name="tasks.get_emails")
def get_emails(htmlSource):
	print('Collecting email from source.')
	try:
		email_pattern = re.compile("[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z]+[\.-0-9a-zA-Z]*\.[a-zA-Z]+")
		found_emails = re.findall(email_pattern, htmlSource)
		unique_emails = list(set(found_emails))
		return unique_emails
	except Exception as exc:
		print('htmlSource {0} gave error: {1!r}'.format(htmlSource, exc))
	# return found_emails

@celery.task(name="tasks.urlopen")
def urlopen(url):
	#some things to look out for: 
	# - should i retry for links that might be dead? timeout
	# - getting poop input screws up getting emails, what should i do?
	# - 
	print('Opening: {0}'.format(url))
	try:
		socket = urllib.urlopen(url)
		html = socket.read()
		socket.close()
		return html