示例#1
0
 def xlsx_create_class(cls, _name: str, _filename: str, _maker: int) -> int:
     _data = pd.read_excel(f'class_rosters/{_filename}')
     new_data = list(
         zip(list(_data['Student']), list(_data['E-mail Address'])))
     _new_rows = [{
         'name': ' '.join(a.split(', ')[::-1]),
         'email': b,
         'role': False
     } for a, b in new_data]
     final_rows = [
         user_manager.User.add_user(i).__dict__ for i in _new_rows
     ]
     _new_id = (lambda x: 1 if not x else max(x) + 1)([
         a for a, _ in tigerSqlite.Sqlite('student_classes.db').get_id_data(
             'classes')
     ])
     tigerSqlite.Sqlite('student_classes.db').insert(
         'classes', ('id', _new_id), ('data', {
             'name':
             _name,
             'owner':
             _maker,
             'students': [{
                 'classid': i,
                 **a
             } for i, a in enumerate(final_rows, 1)]
         }))
     return _new_id
示例#2
0
 def csv_create_class(cls, _name: str, _filename: str, _maker: int) -> int:
     _data = csv.reader(open(f'class_rosters/{_filename}'))
     _new_rows = [{
         'name': re.sub('^\s+|\s+$', '', a),
         'email': re.sub('^\s+|\s+$', '', b),
         'role': False
     } for a, b in _data]
     final_rows = [
         user_manager.User.add_user(i).__dict__ for i in _new_rows
     ]
     _new_id = (lambda x: 1 if not x else max(x) + 1)([
         a for a, _ in tigerSqlite.Sqlite('student_classes.db').get_id_data(
             'classes')
     ])
     tigerSqlite.Sqlite('student_classes.db').insert(
         'classes', ('id', _new_id), ('data', {
             'name':
             _name,
             'owner':
             _maker,
             'students': [{
                 'classid': i,
                 **a
             } for i, a in enumerate(final_rows, 1)]
         }))
     return _new_id
示例#3
0
 def __init__(self, query, block_type):
     self.block_type = block_type
     self.query = query
     self.users = [
         i for i in tigerSqlite.Sqlite(
             '/home/jamespetullo/gitmeet/userprofiles.db').
         get_username_name_avatar_email_summary_id_extra('users')
         if str(self.query).lower() in str(i[0]).lower()
     ]
     self.projects = [
         i for i in tigerSqlite.Sqlite(
             '/home/jamespetullo/gitmeet/projects.db').
         get_projectname_description_owner_id_team_teamneeded_requests_extra(
             'projects') if str(self.query).lower() in str(i[0]).lower()
         or str(self.query).lower() in str(i[1]).lower()
         or str(self.query.lower()) in str(i[2]).lower()
     ]
     self.jobs = list(
         itertools.chain(
             *[[[job] + [i[0], i[1]] for job in filter(None, i[-1])
                if str(self.query).lower() in (
                    ' ' if not job['job_description'] else str(
                        job['job_description']).lower()) or
                str(self.query).lower() in (' ' if not job['job_title'] else
                                            str(job['job_title']).lower())]
               for i in tigerSqlite.Sqlite(
                   '/home/jamespetullo/gitmeet/projects.db').
               get_projectname_owner_teamneeded('projects') if i[-1]]))
示例#4
0
 def create_channel(cls, _owner_id, _channel_name):
     _date = datetime.datetime.now()
     _current_channels = tigerSqlite.Sqlite('/Users/jamespetullo/sup/channels.db').get_id('channels')
     _time = '{} {}'.format('-'.join(str(getattr(_date, i)) for i in ['month', 'day', 'year']), ':'.join(str(getattr(_date, i)) for i in ['hour', 'minute', 'second']))
     _row = [len(_current_channels)+1, _time, {'name':_channel_name, 'description':None, 'rules':None, 'avatar':None, 'default_role':'Standard user', 'can_pm':True}, _owner_id, [], [], [], [], [], '', '']
     _t = tigerSqlite.Sqlite('/Users/jamespetullo/sup/channels.db')
     _t.insert('channels', *list(zip(cls.headers, _row)))
     return cls(*_row)
示例#5
0
 def validate_user_registration(cls, _name: str, _email: str) -> dict:
     if any(c == _name for c, _ in tigerSqlite.Sqlite(
             'user_credentials.db').get_name_email('credentials')):
         return {'success': 'False', 'for': 'name'}
     if any(b == _email for _, b in tigerSqlite.Sqlite(
             'user_credentials.db').get_name_email('credentials')):
         return {'success': 'False', 'for': 'email'}
     return {'success': 'True'}
示例#6
0
def remove_top_project(projectname, username):
    if not any(a == projectname and b == username
               for a, b in tigerSqlite.Sqlite(
                   'top_projects.db').get_projectname_owner('best')):
        raise ValueError('project "{}" with creator @{} not found'.format(
            projectname, username))
    tigerSqlite.Sqlite('top_projects.db').delete('best',
                                                 ('projectname', projectname))
    click.echo('project removed')
示例#7
0
 def _wrapper(_inst, *args):
     _t =  f(_inst, *args)
     #print('for val in cached ', _t, type(_t))
     #num real, url text, html text, css text, js text
     if any(int(c) == _inst.tab for c, *_ in sqlite3.connect('browser_settings/cached_tabs.db').cursor().execute("SELECT * FROM cached_tabs")):
         tigerSqlite.Sqlite('browser_settings/cached_tabs.db').update('cached_tabs', [['url', _inst.url]]+[[i, _t[i] if i == 'html' else '' if i not in _t else open(f'jnet_static_folder/on_response.{i}').read()] for i in ['html', 'css', 'js']], [['num', _inst.tab]])
     else:
         tigerSqlite.Sqlite('browser_settings/cached_tabs.db').insert('cached_tabs', ('num', _inst.tab), ('url', _inst.url), *[(i, _t[i] if i == 'html' else '' if i not in _t else open(f'jnet_static_folder/on_response.{i}').read()) for i in ['html', 'css', 'js']])
     return _t
示例#8
0
 def remove_event(cls, _user: int, _payload: dict) -> typing.Callable:
     _all_events = [
         b for a, b in tigerSqlite.Sqlite(
             'user_calendars.db').get_id_events('calendars')
         if int(a) == int(_user)
     ][0]
     new_events = [i for i in _all_events if Event(i) != Event(_payload)]
     tigerSqlite.Sqlite('user_calendars.db').update(
         'calendars', [['events', new_events]], [['id', int(_user)]])
     return cls.by_week(user=_user, expedient=True)
示例#9
0
def delete_history(_ids = None, by_id = False):
    conn = sqlite3.connect('browser_settings/browser_history.db')
    if not by_id:
        conn.executemany("DELETE FROM history WHERE id=?", [[i] for i in _ids])

    else:
        conn.execute("DELETE FROM history")
    conn.commit()
    conn.close()
    for a, b in tigerSqlite.Sqlite('browser_settings/browser_tab_history.db').get_id_tabs('tab_history'):
        tigerSqlite.Sqlite('browser_settings/browser_tab_history.db').update('tab_history', [['tabs', [] if by_id else [i for i in b if i['id'] not in _ids]]], [['id', a]])
示例#10
0
 def update_links(cls, _id:str, _raw_data:typing.List[typing.Tuple[str, str]]) -> None:
     link = collections.namedtuple('link', ['name', 'icon', 'id'])
     _l = [['Youtube', "fab fa-youtube"], ['Google+', "fab fa-google-plus-g"], ['Linkedin', "fab fa-linkedin-in"], ['Facebook', "fab fa-facebook-square"], ['Personal Site', 'fas fa-link'], ['Github', "fab fa-github"], ['Twitter', "fab fa-twitter"]]
     social_links = [link(*a, i) for i, a in enumerate(_l, 1)]
     _base = {i.id:i.name for i in social_links}
     _extra = {i.name:i.icon for i in social_links}
     _final_dict = {_base[int(re.findall('\d+', a)[0])]:b for a, b in _raw_data}
     current_links = [[Social(*i) for i in b] for a, b in tigerSqlite.Sqlite('/Users/jamespetullo/sup/users.db').get_id_links('users') if int(a) == int(_id)][0]
     _converter = {i.name:i.link for i in current_links}
     _final_links = [[b, a, _final_dict[a] if a in _final_dict else _converter[a]] for a, b in _extra.items() if a in _converter or (a in _final_dict and _final_dict[a])]
     tigerSqlite.Sqlite('/Users/jamespetullo/sup/users.db').update('users', [['links', _final_links]], [['id', _id]])
示例#11
0
 def _wrapper(site_obj, url, _tab, request_type, update=False, forms={}) -> typing.Any:
     d = datetime.datetime.now()
     timestamp = '-'.join(str(getattr(d, i)) for i in ['month', 'day', 'year'])+' '+':'.join(str(getattr(d, i)) for i in ['hour', 'minute', 'second'])
     current_id =  _tab.tabid
     #[_max_history_id(), url.app_name, url.path, site_obj.ip, url.server, timestamp]
     headers = ['id', 'app_name', 'url_path', 'ip', 'server', 'timestamp']
     if update:
         _current = [b for a, b in tigerSqlite.Sqlite('browser_settings/browser_tab_history.db').get_id_tabs('tab_history') if a == current_id][0]
         tigerSqlite.Sqlite('browser_settings/browser_tab_history.db').update('tab_history', [['tabs', _current+[dict(zip(headers, [_max_history_id()-1, url.app_name, url.path, site_obj.ip, url.server, timestamp]))]]], [['id', current_id]])
     else:
         tigerSqlite.Sqlite('browser_settings/browser_tab_history.db').insert('tab_history', ('id', current_id), ('tabs', [dict(zip(headers, [_max_history_id(), url.app_name, url.path, site_obj.ip, url.server, timestamp]))]))
     return f(site_obj, url, _tab, request_type, update=update, forms=forms)
示例#12
0
 def create_group(cls, _user: int, _payload: dict) -> None:
     [_groups] = [
         b for a, b in tigerSqlite.Sqlite('user_groups.db').get_id_listings(
             'groups') if int(a) == int(_user)
     ]
     _d = datetime.datetime.now()
     print(_payload)
     _new_groups = _groups + [{
         **_payload, 'timestamp':
         '-'.join(str(getattr(_d, i)) for i in ['year', 'month', 'day'])
     }]
     tigerSqlite.Sqlite('user_groups.db').update(
         'groups', [('listings', _new_groups)], [('id', _user)])
     return str(len(_new_groups))
示例#13
0
 def create_calendar_event(cls, _user: int, _payload: dict) -> None:
     _timestamps = cls.event_datetime(_payload)
     new_payload = {
         'timestamp': str(_timestamps.day),
         'created_on': str(datetime.datetime.now()),
         **_payload
     }
     print('resulting payload', new_payload)
     current_events = [
         b for a, b in tigerSqlite.Sqlite(
             'user_calendars.db').get_id_events('calendars') if a == _user
     ][-1]
     tigerSqlite.Sqlite('user_calendars.db').update('calendars', [[
         'events',
         sorted(current_events + [new_payload], key=cls._event_sort_key)
     ]], [['id', _user]])
示例#14
0
 def __init__(self, user):
     self.user = user
     self.recog_db = tigerSqlite.Sqlite('recommendations.db')
     self.user_messages = [
         b for a, b in self.recog_db.get_touser_messages('dev_recs')
         if a == self.user
     ]
     print "in constructor of dev_recogs.py", self.user_messages
示例#15
0
 def events_by_day(cls, _user: int, _day: datetime.date) -> _events_on_day:
     [_event] = [
         b for a, b in tigerSqlite.Sqlite(
             'user_calendars.db').get_id_events('calendars')
         if int(a) == int(_user)
     ]
     return _events_on_day(_day,
                           [Event(i) for i in _event if Event(i)[_day]])
示例#16
0
 def quick_look(cls, _user: int, _payload: dict) -> typing.Callable:
     _user_events = list(
         map(Event, [
             b for a, b in tigerSqlite.Sqlite(
                 'user_calendars.db').get_id_events('calendars')
             if a == _user
         ][-1]))
     return [i for i in _user_events if i == Event(_payload)][0]
示例#17
0
    def get_user(cls, **_kwargs: dict) -> typing.Callable:

        return cls([
            i for i in tigerSqlite.Sqlite('user_credentials.db').
            get_id_name_email_password_settings('credentials')
            if (lambda x: all(x[c] == _kwargs[c] for c in _kwargs)
                )(dict(zip(cls.headers, i)))
        ][0])
示例#18
0
def remove_user(username):
    '''this file is dangerous!! use carefully!!'''
    t = tigerSqlite.Sqlite('/home/jamespetullo/gitmeet/userprofiles.db')
    t.delete('users', ('username', username))
    t1 = tigerSqlite.Sqlite('/home/jamespetullo/gitmeet/projects.db')
    t1.delete('projects', ('owner', username.decode('utf-8')))

    t3 = tigerSqlite.Sqlite('/home/jamespetullo/gitmeet/projects.db')
    t4 = tigerSqlite.Sqlite('/home/jamespetullo/gitmeet/projects.db')
    for a, b in t3.get_projectname_team('projects'):
        if b:
            if any(i[0] == username for i in b):
                print('filtered team',
                      [('team', [i for i in b if i[0] != username])])
                t4.update('projects',
                          [('team', [i for i in b if i[0] != username])],
                          [('projectname', a)])
    confirms = tigerSqlite.Sqlite(
        '/home/jamespetullo/gitmeet/confirmation_db.db')
    confirms.delete('confirmations', ('owner', username))
    recommendations = tigerSqlite.Sqlite(
        '/home/jamespetullo/gitmeet/recommendations.db')
    for a, b in tigerSqlite.Sqlite(
            '/home/jamespetullo/gitmeet/recommendations.db'
    ).get_touser_messages('dev_recs'):
        recommendations.update(
            'dev_recs',
            [('messages', [i for i in b if i['suggested'] != username])],
            [('touser', a)])

    yield
示例#19
0
 def get_maker_classes(cls, _maker: id) -> typing.List[typing.Callable]:
     return All_classes([
         _class({
             'id': int(a),
             **b
         }) for a, b in tigerSqlite.Sqlite(
             'student_classes.db').get_id_data('classes')
         if int(b['owner']) == _maker
     ])
示例#20
0
 def wrapper(**kwargs):
     if not any(
             a == kwargs.get('projectname') and b == kwargs.get('username')
             for a, b in tigerSqlite.Sqlite(
                 'projects.db').get_projectname_owner('projects')):
         raise ProjectDoesNotExist(
             'project "{projectname}" with creator of @{username} does not exist'
             .format(**kwargs))
     return f(**kwargs)
示例#21
0
 def __init__(self, _attr, _col = 'email') -> None:
     _user_data = getattr(tigerSqlite.Sqlite('/Users/jamespetullo/sup/users.db'), f'get_{"_".join(self.__class__.headers)}')('users')
     self.__dict__ = dict(zip(self.__class__.headers, [i for i in _user_data if dict(zip(self.__class__.headers, i))[_col] == _attr][0]))
     _avatar = [i for i in os.listdir('/Users/jamespetullo/sup/static') if i.startswith(str(self.id))]
     self.using_default_cover, self.cover_avatar= self.__class__.cover_photo(self.id)
     self.__dict__.update({'avatar':'https://www.gravatar.com/avatar/{}?d=identicon'.format(md5(self.email.lower().encode('utf-8')).hexdigest()), 'avatar_by_url':True} if not _avatar else {"avatar":_avatar[0], 'avatar_by_url':False})
     self.social = [Social(*i) for i in self.links]
     self.joined_channels = sup_channels.Channel.channels_joined(int(self.id))
     self.owned_channels = sup_channels.Channel.channels_owned(int(self.id))
示例#22
0
 def display_group(cls, _user: int, _id: int) -> typing.Any:
     [_groups] = [
         b for a, b in tigerSqlite.Sqlite('user_groups.db').get_id_listings(
             'groups') if int(a) == int(_user)
     ]
     return {
         'status': 'false'
     } if int(_id) - 1 >= len(_groups) else _group(int(_id),
                                                   _groups[int(_id) - 1])
示例#23
0
 def validate_credentials(cls, _email: str, _password: str) -> dict:
     return {
         'success': 'False',
         'for': 'password'
     } if not any(a == _email and b == _password
                  for a, b in tigerSqlite.Sqlite('user_credentials.db').
                  get_email_password('credentials')) else {
                      'success': 'True'
                  }
示例#24
0
    def select_user(flag=False, avoid=''):
        if flag:
            return list_of_users()

        return {
            a: b
            for a, b in list_of_users().items()
            if any(i[1] == a for i in tigerSqlite.Sqlite('projects.db').
                   get_projectname_owner('projects')) and a != avoid
        }
示例#25
0
 def wrapper(cls, _payload: dict) -> typing.Any:
     _formatted = tigerSqlite.Sqlite('protest_users.db').get_id_data(
         'users')
     _option = [{
         'id': a,
         **b
     } for a, b in _formatted
                if all(b[j] == k for j, k in _payload.items())]
     return _f(cls, _formatted, _payload) if not _option else cls(
         _option[0])
示例#26
0
 def from_pannel_view(cls, _user: int,
                      _range: typing.List[datetime.date]) -> Event:
     [_events] = [
         b for a, b in tigerSqlite.Sqlite(
             'user_calendars.db').get_id_events('calendars')
         if int(a) == int(_user)
     ]
     return [
         Event(i) for i in _events
         if _rangified.rangeify(i) == _rangified(_range)
     ][0]
示例#27
0
def browser_dynamic_app_connector(site_lookup,
                                  parsed_url,
                                  _tab_info,
                                  request_response_type,
                                  update=False,
                                  forms={}):
    if update:
        tigerSqlite.Sqlite('browser_settings/browser_tabs.db').update(
            'tabs', [['ip', site_lookup.ip], ['app', parsed_url.app_name],
                     ['url', parsed_url._original_url],
                     ['path', parsed_url.path], ['session', {}]],
            [['num', _tab_info.tabid]])

    else:
        tigerSqlite.Sqlite('browser_settings/browser_tabs.db').insert(
            'tabs', ('num', _tab_info.tabid), ('ip', site_lookup.ip),
            ('app', parsed_url.app_name), ('url', parsed_url._original_url),
            ('path', parsed_url.path), ('session', {}))
    if parsed_url.app_name not in jnet_utilities.browser_app_listing():
        return {'jnet_jsonify_status': False}
    return {'jnet_jsonify_status':True, **importlib.import_module(f'browser_app_{parsed_url.app_name}').app.build(parsed_url.path, _sessions={}, **json.loads(forms)).content._jsonified_results}
示例#28
0
 def register_user(cls, *args: list) -> dict:
     _name, _email, _password = args
     _check = cls.validate_user_registration(_name, _email)
     if _check['success'] == 'True':
         tigerSqlite.Sqlite('user_credentials.db').insert(
             'credentials', ('id', cls.max_user_id() + 1), ('name', _name),
             ('email', _email), ('password', _password),
             ('settings', {
                 'hide_email': False,
                 'avatar_color': cls._rand_avatar_color()
             }))
     return _check, cls.get_user(email=_email, password=_password)
示例#29
0
 def __iter__(self):
     if not self.user_messages:
         raise StopIteration('no messages')
     message = collections.namedtuple('message',
                                      ['recommending', 'projects', 'user'])
     for m in self.user_messages[0]:
         yield message(
             m['suggested'], m['for_project'],
             gitmeet_user.User([
                 i for i in tigerSqlite.Sqlite('userprofiles.db').
                 get_username_name_avatar_email_summary_id_extra('users')
                 if i[0] == m['suggested']
             ][0]))
示例#30
0
 def personal_events(cls, _user: int, _page: int = 0) -> typing.Callable:
     [_events] = [
         b for a, b in tigerSqlite.Sqlite(
             'user_calendars.db').get_id_events('calendars')
         if int(a) == int(_user)
     ]
     new_events = sorted(_events, key=cls.event_rank_key, reverse=True)
     _groups = [new_events[i:i + 5] for i in range(0, len(new_events), 5)]
     _d = datetime.datetime.now()
     return cls(_page, _page + 1 < len(_groups), [
         _event_wrapper(i, Event(a), _d)
         for i, a in enumerate(_groups[_page], 1)
     ])