コード例 #1
0
def add_user(bot, update):
    root_from_set = config['TELEGRAM']['Root_users']
    root_from_set = root_from_set.split(',')
    is_root = False
    for id in root_from_set:
        if str(id) == str(update.message.chat_id):
            is_root = True
    if not is_root:
        return False
    text = update.message.text
    text = text.replace('/addUser ', '')
    text = text.split(' ')
    adding_chat_it = text[0]
    try:
        adding_user_name = text[1]
    except IndexError:
        adding_user_name = ''
    session = Session()
    q = session.query(TrustedChats).filter(
        TrustedChats.chat_id == str(adding_chat_it))
    if q.count():
        bot.send_message(chat_id=update.message.chat_id,
                         text="This user already in base.")
        bot.send_message(chat_id=update.message.chat_id, text="Bitch")
    else:
        myobject = TrustedChats(chat_id=str(adding_chat_it),
                                name=adding_user_name)
        session.add(myobject)
        session.commit()
        bot.send_message(chat_id=update.message.chat_id,
                         text="User was added.")
    session.close()
コード例 #2
0
def addUser(username,
            refresh_token,
            playlist_id_short=None,
            playlist_id_medium=None,
            playlist_id_long=None):
    session = Session()
    id_exists = session.query(User.id).filter_by(username=username).scalar()

    # new user
    if id_exists == None:
        user = User(username=username,
                    refresh_token=refresh_token,
                    playlist_id_short=playlist_id_short,
                    playlist_id_medium=playlist_id_medium,
                    playlist_id_long=playlist_id_long)
        session.add(user)
        logging.info('New auto user: '******'Auto user updated: ' + user.username)

        # only update playlist IDs that are new
        if playlist_id_short != None:
            user.playlist_id_short = playlist_id_short
        if playlist_id_medium != None:
            user.playlist_id_medium = playlist_id_medium
        if playlist_id_long != None:
            user.playlist_id_long = playlist_id_long

    session.commit()
    session.close()
コード例 #3
0
ファイル: cli.py プロジェクト: volfrider/intranet
def add(id, name):
    session = Session()
    q = session.query(TrustedChats).filter(TrustedChats.chat_id == str(id))
    if q.count():
        click.secho(click.style('ChatId must be unique.', fg='red',
                                blink=True),
                    err=True)
        click.secho("Use \"list\" to see all trusted chat ids.")
    else:
        myobject = TrustedChats(chat_id=str(id), name=name)
        session.add(myobject)
        session.commit()
        click.echo('ChatId {} was added.'.format(id))
    session.close()
コード例 #4
0
        "email":"*****@*****.**"
    }, {
        "username":"******",
        "email":"*****@*****.**"
    }, {
        "username":"******",
        "email":"*****@*****.**"
    },
]



local_session=Session(bind=engine)

new_user=User(username="******",email="*****@*****.**")

local_session.add(new_user)

local_session.commit()


# for u in users:
#     new_user=User(username=u["username"],email=u["email"])
    
#     local_session.add(new_user)

#     local_session.commit()

#     print(f"Added {u['username']}")

コード例 #5
0
furious_7.actors = [dwayne_johnson]
pain_and_gain.actors = [dwayne_johnson, mark_wahlberg]

# 7 - add contact details to actors
matt_contact = ContactDetails("415 555 2671", "Burbank, CA", matt_damon)
dwayne_contact = ContactDetails("423 555 5623", "Glendale, CA", dwayne_johnson)
dwayne_contact_2 = ContactDetails("421 444 2323", "West Hollywood, CA", dwayne_johnson)
mark_contact = ContactDetails("421 333 9428", "Glendale, CA", mark_wahlberg)

# 8 - create stuntmen
matt_stuntman = Stuntman("John Doe", True, matt_damon)
dwayne_stuntman = Stuntman("John Roe", True, dwayne_johnson)
mark_stuntman = Stuntman("Richard Roe", True, mark_wahlberg)

# 9 - persists data
session.add(bourne_identity)
session.add(furious_7)
session.add(pain_and_gain)

session.add(matt_contact)
session.add(dwayne_contact)
session.add(dwayne_contact_2)
session.add(mark_contact)

session.add(matt_stuntman)
session.add(dwayne_stuntman)
session.add(mark_stuntman)

# 10 - commit and close session
session.commit()
session.close()