Небольшой трик с регулярными выражениями который редко вижу в чужом коде.
Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста.
>>> text = '''
>>> Alex:8999123456
>>> Mike:+799987654
>>> Oleg:+344456789
>>> '''
Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн:
(\w+):([\d+]+)
Как мы будем формировать словарь из найденных групп?
>>> import re
>>> results = []
>>> for match in re.finditer(r"(\w+):([\d+]+)", text):
>>> results.append({
>>> "name": match.group(1),
>>> "phone": match.group(2)
>>> })
>>> print(results)
[{'name': 'Alex', 'phone': '8999123456'}, ...]
Можно немного сократить запись используя zip
>>> results = []
>>> for match in re.finditer(r"(\w+):([\d+]+)", text):
>>> results.append(dict(zip(['name', 'phone'], match.groups())))
Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря.
>>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text):
>>> results.append(match.groupdict())
То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись:
(?P<group-name>...)
Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка
>>> name = match['name']
Либо забрать сразу весь словарь методом groupdict()
>>> match.groupdict()
#tricks#regex
DataBackup
An easy-to-use backup Libre application for Android, however your phone needs to be rooted , unless a ROM were to include it as a system app
Support for #multi-user/double backup: same backup/restore on multiple partitions!
Cloud: fully supports #Rclone, which can perform local mounting of network drives from various service providers.
100% data integrity: all data will be retained and there is no need to reconnect or download additional packages.
Complete: Split Apk, Arm32, Arm64, x86, x86_64, Android9+.
Fast: Support: tar lz4 zstd (default).
GitHub - XayahSuSu/Android-DataBackup: 数据备份 DataBackup for Android - https://github.com/XayahSuSuSu/Android-DataBackup
Reminder : to install it via F-Droid first add the Izzy repository to F-Droid ( settings - repositories/sources)
IzzyOnDroid F-Droid Repository -
https://apt.izzysoft.de/fdroid/
#Backup #Android
Rclone Remount
Remount cloud storage locally during boot via rclone & fusermount directly on your Android powered smart device.
Virtually limitless storage expansion with support for dozens of cloud providers including Dropbox, GDrive, OneDrive, SFTP & many more. Extremely useful for devices without physical storage expansion capabilities. Also great for streaming large media files without need for full caching. Binaries compiled using Termux.
Features:
Support for arm, arm64, & x86
Huge list of supported cloud storage providers
Apps with ability to specify paths can access /mnt/cloud/
Most file explorers work just fine (issue #9)
Mount points use names of remote(s) in rclone.conf
Specify custom rclone params for each remote via /sdcard/.rclone/.REMOTE.param
Access remotes via http://127.0.0.1:38762
Access remotes via ftp://127.0.0.1:38763
Mount bind to /sdcard/ (see issue #5)
Support for Work Profiles
https://github.com/Magisk-Modules-Repo/com.piyushgarg.rclone
#rclone#remount#cloud#alternatives
RCX
Android GUI for rclone. Manage files across many cloud services in a simple way under one interface.
https://x0b.github.io
https://f-droid.org/packages/io.github.x0b.rcx
https://github.com/x0b/rcx
@nogoolag
#rcx#rclone#cloud#alternatives