число d называется секретной экспонентой; обычно оно вычисляется при помощи расширенного алгоритма Евклида
In [1]: from ast import literal_eval
In [2]: literal_eval("[1, 2, 3]")
Out[2]: [1, 2, 3]
schtasks.exe /run /tn имя_задачи
~$ python --version
Python 2.7.18
~$ python -m pip --version
pip 20.2.3 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --user
su -
apt-get install sudo
usermod -a -G sudo <имя_пользователя>
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
db_connections = []
db1 = sqlite3.connect('baza1.db')
db_connections.append(db1)
db2 = sqlite3.connect('area51.db')
db_connections.append(db2)
...
for db in db_connections:
db.close()
import json
data = json.loads("""
{"2000000003": {"amv": true, "amvl": true, "whoa": true},
"2000000004": {"amv": true, "amvl": true, "whoa": true}}
""")
data["2000000004"]["amv"] = True
key = "2000000004"
with open("file.json","r") as inp, open("temp.json", "w") as out:
for line in inp:
linej=json.loads(line)
if key in linej:
linej[key]["amv"] = False
line = json.dumps(linej)+"\n"
out.write(line)
os.remove("file.json")
os.rename("temp.json","file.json")
{"2000000003": {"amv": true, "amvl": true, "whoa": true}}
{"2000000004": {"amv": true, "amvl": true, "whoa": true}}
import json
target_id = '2000000004'
result = []
with open('test.json', encoding='UTF-8') as source, \
open('test_out.json', 'w', encoding='UTF-8') as out:
for line in source:
parsed_json_line = json.loads(line)
if target_id in parsed_json_line.keys():
parsed_json_line[target_id]['amv'] = False
out.write(f'{json.dumps(parsed_json_line)}\n')
import json
result = []
with open('test.json', encoding='UTF-8') as f:
for line in f:
result.append(json.loads(line))
target_id = '2000000004'
for i, item in enumerate(result):
if target_id in item.keys():
result[i][target_id]['amv'] = False
with open('test_out.json', 'w', encoding='UTF-8') as f:
for item in result:
f.write(f'{json.dumps(item)}\n')
{"2000000003": {"amv": true, "amvl": true, "whoa": true}}
{"2000000004": {"amv": false, "amvl": true, "whoa": true}}
config = {'-1111111': {'/kick': False, '/command': True, '/example': True}, '-22222': {'/kick': True, '/command': False, '/example': False}}
import json
# запись конфига в файл
with open('config.json', 'w', encoding='utf-8') as f:
json.dump(config, f)
# чтение собственно
with open('config.json', 'r', encoding='utf-8') as f:
config = json.load(f)
messages.getChat
недоступен.messages.getConversationsById
def get_chat_title(chat):
return vk.method("messages.getConversationsById", {"peer_ids": chat})['items'][0]['chat_settings']['title']
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
print('Название беседы: ' + get_chat_title(event.obj.peer_id))
except Exception as e:
print(repr(e))