コード例 #1
0
ファイル: database.py プロジェクト: jackzliu9/CIS192_FINAL
def initDB():
  with app.app_context():
  	db = getDB()
  	with app.open_resource(app.config['SCHEMA'], mode='r') as f:
			db.cursor().executescript(f.read())
			print "Initialized Database."
  	db.commit()
コード例 #2
0
ファイル: __init__.py プロジェクト: JiehuiSun/DataTools
def send_mail(title: str,
              content: str,
              user_mail_list: list,
              attachments: list = None,
              html_content: str = None,
              bcc: list = None,
              send_date: str = None):
    params = {
        "subject": title,
        "recipients": user_mail_list,
        "body": content,
        "html": html_content,
        "sender": current_app.config["MAIL_USERNAME"],
        "bcc": bcc,
        # "attachments": attachments,
        "date": send_date,
    }

    msg = Message(**params)
    from application import app
    if attachments:
        for i in attachments:
            with app.open_resource(f"../ex_file/{i}") as fp:
                msg.attach(
                    i.split("/")[-1],
                    mimetypes.guess_type("aaa.txt")[0], fp.read())

    from base import mail
    mail.send(msg)
コード例 #3
0
ファイル: loader.py プロジェクト: francosimonetti/pfamserver
 def load_sql(self, table_name):
     filename = '{:}{:}.sql'.format(self.backup_path, table_name)
     print(
         "\t\tCreating {:} structure into the database.".format(table_name))
     with app.open_resource(filename, mode='r') as f:
         cmds = f.read().decode('unicode_escape').encode('ascii', 'ignore')
         cmds = cmds.replace('NOT NULL', '').split('\n')
         keys = []
         if table_name in patched_pk:
             keys = patched_pk[table_name].split(',')
             field_name = lambda r: any(
                 map(lambda e: e in keys, re.findall('`[^`]*`', r)))
             cmds = map(
                 lambda r: r
                 if field_name(r) else r.replace('DEFAULT NULL', ''), cmds)
         cmds = filter(lambda c: c and c[0] not in ['/', '-'], cmds)
         cmds = ''.join(cmds)
         cmds = cmds.replace("`created` datetime DEFAULT NULL",
                             "`created` datetime NULL DEFAULT NULL")
         if 'PRIMARY KEY' not in cmds:
             if table_name in patched_pk:
                 keys = map(lambda k: "`" + k + "`", keys)
                 cmds = cmds.replace(
                     ') ENGINE',
                     ', PRIMARY KEY ({:})) ENGINE'.format(','.join(keys)))
         cmds = sqlparse.split(cmds)
         with warnings.catch_warnings():
             warnings.filterwarnings('ignore', 'unknown table')
             warnings.filterwarnings('ignore',
                                     'Duplicate index',
                                     append=True)
             map(self.execute, cmds)
         return True
コード例 #4
0
        def generate(job_id, size):
            """Generate a thumbnail for the requested job id, at the requested
            size. If the size is None, we return the orginal.
            """
            filename = 'thumbnail_{0}.png'.format(job_id)
            path_thumbnail_original = join(app.config['TMP_FOLDER'], filename)
            # Check that the original file exsits
            if os.path.isfile(path_thumbnail_original):
                # Thumbnail file object that is returned by the view
                thumb_file = None
                # Check if we are asking for a thumbnail
                if size:
                    # Define expected path for thumbnail
                    root, ext = os.path.splitext(path_thumbnail_original)
                    path_thumbnail_resized = "{0}.{1}{2}".format(root, size, ext)
                    # Check if the thumbnails has been generated already
                    if os.path.isfile(path_thumbnail_resized):
                        # Modification date for the original image
                        thumb_original_timestamp = time.ctime(
                            os.path.getmtime(path_thumbnail_original))
                        # Modification date for the generated thumbnail
                        thumb_resized_timestamp = time.ctime(
                            os.path.getmtime(path_thumbnail_resized))
                        # Check if the original file is more recent than the resized
                        if thumb_original_timestamp > thumb_resized_timestamp:
                            thumb_file = make_thumbnail(
                                path_thumbnail_original,
                                path_thumbnail_resized,
                                size)
                        else:
                            thumb_file = open(path_thumbnail_resized, 'r')
                    else:
                        # Generate a new thumbnail, defaults to small
                        thumb_file = make_thumbnail(
                            path_thumbnail_original,
                            path_thumbnail_resized,
                            size)

                # If no thumb file is found, open the original image instead
                if not thumb_file:
                    thumb_file = open(str(path_thumbnail_original), 'r')
                return thumb_file.read()
            # If no resized file is available (job did not start or is running)
            else:
                with app.open_resource('static/missing_thumbnail.png') as thumb_file:
                    return thumb_file.read()
            return False
コード例 #5
0
ファイル: __init__.py プロジェクト: hadengriffiths/flamenco
        def generate(job_id, size):
            """Generate a thumbnail for the requested job id, at the requested
            size. If the size is None, we return the orginal.
            """
            filename = 'thumbnail_{0}.png'.format(job_id)
            path_thumbnail_original = join(app.config['TMP_FOLDER'], filename)
            # Check that the original file exsits
            if os.path.isfile(path_thumbnail_original):
                # Thumbnail file object that is returned by the view
                thumb_file = None
                # Check if we are asking for a thumbnail
                if size:
                    # Define expected path for thumbnail
                    root, ext = os.path.splitext(path_thumbnail_original)
                    path_thumbnail_resized = "{0}.{1}{2}".format(root, size, ext)
                    # Check if the thumbnails has been generated already
                    if os.path.isfile(path_thumbnail_resized):
                        # Modification date for the original image
                        thumb_original_timestamp = time.ctime(
                            os.path.getmtime(path_thumbnail_original))
                        # Modification date for the generated thumbnail
                        thumb_resized_timestamp = time.ctime(
                            os.path.getmtime(path_thumbnail_resized))
                        # Check if the original file is more recent than the resized
                        if thumb_original_timestamp > thumb_resized_timestamp:
                            thumb_file = make_thumbnail(
                                path_thumbnail_original,
                                path_thumbnail_resized,
                                size)
                        else:
                            thumb_file = open(path_thumbnail_resized, 'r')
                    else:
                        # Generate a new thumbnail, defaults to small
                        thumb_file = make_thumbnail(
                            path_thumbnail_original,
                            path_thumbnail_resized,
                            size)

                # If no thumb file is found, open the original image instead
                if not thumb_file:
                    thumb_file = open(str(path_thumbnail_original), 'r')
                return thumb_file.read()
            # If no resized file is available (job did not start or is running)
            else:
                with app.open_resource('static/missing_thumbnail.png') as thumb_file:
                    return thumb_file.read()
            return False
コード例 #6
0
def send_attendance_certificate(email):
    try:
        msg = Message('Sertifikat Kehadiran dari WikiLatih',
                      sender='*****@*****.**',
                      recipients=[email])
        msg.body = "Selamat atas kehadiran Anda di kegiatan pelatihan WikiLatih. " \
                   "Berikut dilampirkan dokumen sertifikat kehadiran. Terima kasih."

        with app.open_resource(
                "static/pdf/certificate_of_attendance.pdf") as fp:
            msg.attach("certificate_of_attendance.pdf", "application/pdf",
                       fp.read())

        mail.send(msg)
        return True
    except:
        return False
コード例 #7
0
def send_qualification_certificate(email):
    try:
        print(email)
        msg = Message('Sertifikat Kualifikasi dari WikiLatih',
                      sender='*****@*****.**',
                      recipients=[email])
        msg.body = "Selamat, Anda telah lulus uji kompetensi kegiatan pelatihan WikiLatih. " \
                   "Berikut dilampirkan dokumen sertifikat kualifikasi. Terima kasih."

        with app.open_resource(
                "static/pdf/certificate_of_qualification.pdf") as fp:
            msg.attach("certificate_of_qualification.pdf", "application/pdf",
                       fp.read())

        mail.send(msg)
        return True
    except:
        return False
コード例 #8
0
ファイル: __init__.py プロジェクト: EVMosaic/flamenco
                        filename, ext = os.path.splitext(filename)
                        im = Image.open(file_path_original_thumbnail)
                        try:
                            im.thumbnail(size)
                            im.save(file_path_resized_thumbnail)
                        except IOError, e:
                            logging.error(' making the thumbnail: {0}'.format(e))
                        else:
                            thumb_file = open(file_path_resized_thumbnail, 'r')

                if not thumb_file:
                    thumb_file = open(str(file_path_original_thumbnail), 'r')

                return thumb_file.read()
            else:
                with app.open_resource('static/missing_thumbnail.png') as thumb_file:
                    return thumb_file.read()
            return False
        bin = generate()
        if bin:
            return Response(bin, mimetype='image/png')
        else:
            return '', 404


class JobFileApi(Resource):
    def get(self, job_id):
        """Given a job_id returns the jobzip file
        """
        job = Job.query.get(job_id)
        serverstorage = app.config['SERVER_STORAGE']
コード例 #9
0
 def execute_sql(resource_name):
     """Helper function to run a SQL script on the database."""
     with app.open_resource(resource_name, mode='r') as f:
         g.cursor.execute(f.read())
     g.connection.commit()
コード例 #10
0
ファイル: SqlLiteConnector.py プロジェクト: karma243/shareit
def init_db():
    with app.app_context():
        db = get_db()
        with app.open_resource('databases/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()
コード例 #11
0
ファイル: tests.py プロジェクト: nyshas/home-church-manager
 def execute_script(resource_name):
     """Helper function to run a SQL script on the test database."""
     with app.open_resource(resource_name, mode='r') as f:
         g.db.cursor().executescript(f.read())
     g.db.commit()
コード例 #12
0
ファイル: views.py プロジェクト: Dpens/Link
def init_db():
    with closing(connect_db()) as db:
        with app.open_resource('schema.sql') as f:
            db.cursor().executescript(f.read())
        db.commit()
コード例 #13
0
ファイル: tests.py プロジェクト: rrc4/homegrown
 def execute_sql(resource_name):
     with app.open_resource(resource_name, mode='r') as f:
         g.cursor.execute(f.read())
     g.connection.commit()
コード例 #14
0
                    size = 128, 128
                    file_path_resized_thumbnail = os.path.join(
                        app.config['TMP_FOLDER'], filename + ".thumbnail.png")
                    if not os.path.isfile(file_path_resized_thumbnail):
                        filename, ext = os.path.splitext(filename)
                        im = Image.open(file_path_original_thumbnail)
                        try:
                            im.thumbnail(size)
                            im.save(file_path_resized_thumbnail)
                        except IOError, e:
                            logging.error(
                                ' making the thumbnail: {0}'.format(e))
                        else:
                            thumb_file = open(file_path_resized_thumbnail, 'r')

                if not thumb_file:
                    thumb_file = open(str(file_path_original_thumbnail), 'r')

                return thumb_file.read()
            else:
                with app.open_resource(
                        'static/missing_thumbnail.png') as thumb_file:
                    return thumb_file.read()
            return False

        bin = generate()
        if bin:
            return Response(bin, mimetype='image/png')
        else:
            return '', 404