Esempio n. 1
0
    def run(self):
        global constants_service
        self.img_url = None
        self.urls = []
        for cur_format in self.user_config['codesnippet-formats']:
            file_name = self.uuid + "." + cur_format
            file_path = ConstantsService.get_value(
                'dist_store') + "/" + file_name
            file_url = ConstantsService.get_value(
                'enkidu_url') + '/dist/' + file_name
            formatter = get_formatter_for_filename(
                file_name,
                style=get_style_by_name(self.user_config['theme']),
                font_size=self.user_config['image-fontsize'],
                noclasses=True,
                linenos=True)
            if "jpg" in file_name or "gif" in file_name or "png" in file_name:
                self.img_url = file_url

            formatter.title = self.create_snippet_title()
            formatter.full = True
            lexer = guess_lexer(self.payload.encode())
            result = highlight(self.payload, lexer, formatter)
            open(file_path, 'wb').write(
                str.encode(result) if type(result) is str else result)
            self.urls.append(file_url)
Esempio n. 2
0
 def init_default_settings(self, db, user_name, display_name):
     with open(ConstantsService.get_value(
             'default_settings_path')) as json_file:
         default_settings = json.loads(json_file.read())
         default_settings["display_name"] = display_name
         db[user_name] = json.dumps(default_settings)
         return default_settings
Esempio n. 3
0
def dist(filename):
    global constants_service
    try:
        return send_from_directory(ConstantsService.get_value('dist_store'),
                                   filename)
    except IOError:
        abort(404)
Esempio n. 4
0
 def get_message(self):
   with open(ConstantsService.get_value('public_key_file')) as public_key_file:
     return {
       "text": public_key_file.read()}
Esempio n. 5
0
 def get_settings(self, user_name):
     with dbm.open(ConstantsService.get_value('db_path'), 'c') as db:
         return json.loads(
             db[user_name]
         ) if user_name in db else self.init_default_settings(
             db, user_name, "unknown player one")
Esempio n. 6
0
 def set_settings(self, user_name, settings):
     with dbm.open(ConstantsService.get_value('db_path'), 'c') as db:
         db[user_name] = json.dumps(settings)
Esempio n. 7
0
 def get_message(self):
     return {
         "text":
         "```\n" +
         open(ConstantsService.get_value("help_file"), 'r').read() + "\n```"
     }
Esempio n. 8
0
        'wsgi': {
            'class': 'logging.StreamHandler',
            'stream': 'ext://sys.stdout',
            'formatter': 'default'
        }
    },
    'root': {
        'level': 'INFO',
        'handlers': ['wsgi']
    }
})

app = Flask(__name__)

credentials = service_account.Credentials.from_service_account_file(
    ConstantsService.get_value('credentials'),
    scopes=ConstantsService.get_value('scopes'))
chat = build('chat', 'v1', credentials=credentials)

async_task_stack = []


def checkAsyncTasks():
    for cur_task in async_task_stack:
        if cur_task.is_finished():
            chat.spaces().messages().create(
                parent=cur_task.get_target_space_name(),
                body=cur_task.get_message()).execute()
            async_task_stack.remove(cur_task)