interpret communication from / dev files - linux

I want to intercept the content emitted by the keyboard,
I know that each device has a file linked to it,
my question is how to intercept a 'specific' usb port and where to find the documentation to interpret the data
Sorry for the english (google translator)

Based on: https://sergioprado.org/implementando-um-teclado-virtual-no-linux/
The file that abstracts event capture from input devices like mouse, keyboard, joysticks, touch screens, etc. is / dev / input
You can use an "evtest" tool to check which device is related to a given file: example evtest / dev / input / event4
Português
Baseado em: https://sergioprado.org/implementando-um-teclado-virtual-no-linux/
O arquivo que abstrai a captura de eventos de dispositivos de entrada como mouse, teclado, joysticks, touch screens, etc é /dev/input
Você pode usar a ferramenta "evtest" para verificar qual o dispositivo relacionado à determinado arquivo: exemplo evtest /dev/input/event4

Related

Request com Python [closed]

Closed. This question is not written in English. It is not currently accepting answers.
Stack Overflow is an English-only site. The author must be able to communicate in English to understand and engage with any comments and/or answers their question receives. Don't translate this post for the author; machine translations can be inaccurate, and even human translations can alter the intended meaning of the post.
Closed 3 days ago.
Improve this question
Opa, sou novo por aqui, ainda não entendo algumas regras, mas estou com uma dúvida sobre a biblioteca "request" em python, não somente em python mas no request de uma forma geral. Minha dúvida é a seguinte: Estou acessando uma API (GraphQL do GitHub) e ela me limita a visualizar apenas 100 commits, como faço para poder obter os demais commits, sendo que toda vez que faço um request de forma sequencial ele me retorna os mesmos 100 elementos?
O que tentei foi exatamente executar dois requests seguidos, esperava receber 200 commits, mas recebi os mesmos 100.

Zimbra id messages script

I hope I can explain what I want to do, I am creating a script for zimbra that allows me to capture the ID of the messages of each user and get it in a txt extension file, and the command that allows me to do this is as follows:
zmmailbox -z -m info#domain.com search -l 2 "in:/inbox"
this command outputs the following:
num: 2, more: true
Id Type From Subject Date
-482 conv Twitter Kevin K. Sullivan twitteó: Muy emocionado de poder 06/14/22 06:02
-481 conv Twitter Netto, únete a la conversación ya mismo 06/10/22 05:15
now what I need is to be able to add another column where I can add the user that is affecting the script.
num: 2, more: true
Id Type From Subject Date User
-482 conv Twitter Kevin K. Sullivan twitteó: Muy emocionado de poder 06/14/22 06:02 info#domain.com
-481 conv Twitter Netto, únete a la conversación ya mismo 06/10/22 05:15 info#domain.com
I publish the actual script.
https://pastebin.com/7S1uFcY3

Reading a semicolon (';') seperated raw text in Python

I have managed to find some solutions online but often without an explanation. I am new to Python and normally choose to rework my data in Excel. I would, however, like to learn how to deal with a problem like the following:
I was given data for Brazil in this form. The website says to "save the file as a csv". It looks like a mess...
Espírito Santo;
Dados;
Ano;População total;Homens;Mulheres;Nascimentos;Óbitos;Taxa de Crescimento Geométrico;Taxa Bruta de Natalidade;Taxa Bruta de Mortalidade;Esperança de Vida ao Nascer;Esperança de Vida ao Nascer - Homens;Esperança de Vida ao Nascer - Mulheres;Taxa de Mortalidade Infantil;Taxa de Mortalidade Infantil - Homens;Taxa de Mortalidade Infantil - Mulheres;Taxa de Fecundidade Total;Razão de Dependência - Jovens 0 a 14 anos;Razão de Dependência - Idosos 65 ou mais anos;Razão de Dependência;Índice de Envelhecimento;
2010;3596057;1772936;1823121;54018;19734;x;15.02;5.49;75.93;71.9;80.19;11.97;13.59;10.28;1.73;34.49;10.17;44.67;29.41;
2011;3642595;1795501;1847094;55387;19923;1.29;15.21;5.47;76.36;72.35;80.59;11.3;12.87;9.66;1.77;33.72;10.41;44.13;30.77;
2012;3689347;1818188;1871159;55207;20142;1.28;14.96;5.46;76.76;72.78;80.96;10.69;12.2;9.1;1.75;32.98;10.68;43.65;32.17;
2013;3736386;1841035;1895351;56785;20396;1.27;15.2;5.46;77.14;73.19;81.31;10.14;11.6;8.6;1.8;32.29;10.97;43.26;34.22;
2014;3784361;1864376;1919985;57964;20676;1.28;15.32;5.46;77.51;73.58;81.64;9.64;11.06;8.15;1.83;31.73;11.31;43.04;35.59;
2015;3832826;1887984;1944842;58703;20979;1.28;15.32;5.47;77.85;73.95;81.95;9.19;10.56;7.74;1.85;31.29;11.69;42.98;37.44;
2016;3879376;1910629;1968747;55091;21282;1.21;14.2;5.49;78.18;74.31;82.24;8.78;10.11;7.38;1.73;30.84;12.13;42.97;39.35;
2017;3925341;1932993;1992348;58530;21624;1.18;14.91;5.51;78.49;74.65;82.5;8.42;9.71;7.06;1.84;30.52;12.61;43.13;41.31;
2018;3972388;1955930;2016458;58342;22016;1.2;14.69;5.54;78.79;74.97;82.76;8.09;9.34;6.77;1.83;30.31;13.14;43.45;43.6;
2019;4018650;1978483;2040167;58106;22419;1.16;14.46;5.58;79.06;75.27;82.99;7.79;9;6.52;1.83;30.12;13.71;43.83;45.45;
I used MSWord to replace the ";" with "," and Excel´s import from text to try and get a more familiar data frame.
How would you approach data in this form using Python? Save as a .csv then import again with pandas? I am hoping for a better solution by keeping it as a """ enclosed string.
You can tell the csv parser what the delimiter is, in this case it is ';'
with open('filepath.csv') as csv_file:
csv.reader(csv_file, delimiter=';')
How do you get this data? As file? As string?
If you have a file you can use pandas to read the csv which would give you a pandas DataFrame:
pandas.read_csv('filepath.csv', delimiterstr=';')
You can find more info here: https://realpython.com/python-csv/

Why Vim is assembling short lines when it should just break the long ones?

I am trying to edit a file using Vim. However, I have just started to use this editor.
This is the text that I am willing to fix (it is in portuguese, but this fact is irrelevant to my doubt):
---
ENUM Questão 1
AREA ETHICS
Janaína é procuradora do município de Oceanópolis e atua, fora da carga horária demandada pela função, como advogada na sociedade de advogados Alfa, especializada em Direito Tributário. A profissional já foi professora na universidade estadual Beta, situada na localidade, tendo deixado o magistério há um ano, quando tomou posse como procuradora municipal.
As you see, the phrase starting with "Janaina é..." is too big. I am trying to make everything have 80 columns.
Hence, I did:
:set textwidth=80
And, in visual mode with all the txt selected, I did:
gq
This is the final output:
--- ENUM Questão 1
AREA ETHICS
Janaína é procuradora do município de Oceanópolis e atua, fora da carga horária
demandada pela função, como advogada na sociedade de advogados Alfa,
especializada em Direito Tributário. A profissional já foi professora na
universidade estadual Beta, situada na localidade, tendo deixado o magistério há
um ano, quando tomou posse como procuradora municipal.
The final result is close to what I want. The only problem is the change from
---
ENUM Questão 1
to
--- ENUM Questão 1
I thought that :set textwidth=80 and :set columns=80 were commands made to break lines which were too long. But, for some reason, this command is assembling the short line with --- and the line with ENUM Questão [num]
Why is this happening?
How can I solve this?
Thanks.
gq can do a lot of things, depending on the formatexpr, formatprg or most possibly the formatoptions setting. see :h gq.
I would use the folloging regex:
:%s/.\{80}/&\r/g
*Note: there is also textwrap in vim, which may help you (:set wrap)

python 3.5 imaplib read gmails as plain text

mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
username = 'MyGmail#gmail.com'
password = 'MyPasswordHere'
mail.login(username, password)
mail.select('INBOX')
typ, data = mail.search(None, 'ALL')
for num in data[0].split():
typ, data = mail.fetch(num, '(RFC822)')
print(data)
exit()
This is a part of the whole output: (not very readable)
[(b'1 (BODY[1] {1115}', b'\r\nHej Bjango For at sikre, at Bjangos side hj=C3=A6lper dig med at n=C3=A5 =\r\ndine m=C3=A5l, giver vi dig her nogle hurtige og nemme forslag til, hvad =\r\ndu kan g=C3=B8re: Opdater dit profilbillede og dit coverbillede =\r\nOverf=C3=B8r=C2=A0billede Tilf=C3=B8j en beskrivelse af din side =\r\nTilf=C3=B8j=C2=A0en=C2=A0beskrivelse Medtag et link til dit website =\r\nTilf=C3=B8j=C2=A0et=C2=A0link Sl=C3=A5 en opdatering eller et billede op =\r\np=C3=A5 din side Opret=C2=A0et=C2=A0opslag Inviter dine venner til at =\r\nsynes godt om din side Inviter=C2=A0dine=C2=A0venner\r\n\r\nHilsen Facebook-teamet\r\n\r\n\r\n\r\n=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=\r\n=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r\nDenne besked blev sendt til infobjango#gmail.com. Hvis du ikke =C3=B8nsker =\r\nat modtage disse e-mails fra Facebook fremover, skal du f=C3=B8lge =\r\nnedenst=C3=A5ende link for at afmelde dem.\r\nhttps://www.facebook.com/o.php?k=3DAS38jnuCT_H5AdZt&u=3D100015358233656&mi=\r\nd=3D548339b6125b3G5af6a3e64c38G0G37b\r\nFacebook, Inc., Attention: Community Support, 1 Hacker Way, Menlo Park, CA =\r\n94025\r\n\r\n'), b')']
So here is my question
How do I make the main part of the mail I received readable?
An example of what I mean by readable:
Dear bjango
This is a mail, which is totally readable without any "<<td style=3D"font-size: 16px; =\r\npadding-bottom: 26px; text-ali>". That's funny I just made a part of this mail unreadable that was supposed to be readable - I hope you get the point.
Best Regards Bjango
This approach does not completely solve my issue with readability:
import email
msg = email.message_from_bytes(data[0][1])
print(msg.get_payload(decode=False))
Output will be as followed:
Hej Bjango For at sikre, at Bjangos side hj=C3=A6lper dig med at n=C3=A5 =
dine m=C3=A5l, giver vi dig her nogle hurtige og nemme forslag til, hvad =
du kan g=C3=B8re: Opdater dit profilbillede og dit coverbillede =
Overf=C3=B8r=C2=A0billede Tilf=C3=B8j en beskrivelse af din side =
Tilf=C3=B8j=C2=A0en=C2=A0beskrivelse Medtag et link til dit website =
Tilf=C3=B8j=C2=A0et=C2=A0link Sl=C3=A5 en opdatering eller et billede op =
p=C3=A5 din side Opret=C2=A0et=C2=A0opslag Inviter dine venner til at =
synes godt om din side Inviter=C2=A0dine=C2=A0venner
Hilsen Facebook-teamet
But none the less, it's a massive improvement
This is the email I intend to get in the output section:
Hej Bjango For at sikre, at Bjangos side hjælper dig med at nå
dine mål, giver vi dig her nogle hurtige og nemme forslag til, hvad
du kan gøre: Opdater dit profilbillede og dit coverbillede
Overfører billeder Tilføj en beskrivelse af din side
Tilføj en beskrivelse Medtag et link til dit website
Tilføj et link Slå en opdatering eller et billede op
på din side Opret et opslag Inviter dine venner til at
synes godt om din side Inviter dine venner
Hilsen Facebook-teamet
Python 3 email parser should work here:
import email
msg = email.message_from_bytes(data[0][1])
payload = msg.get_payload(decode=True)
Assuming your email is encoded as MIME quoted-printable data, you can proceed to decode that using quopri module:
import quopri
message = quopri.decodestring(payload).decode('utf-8')
print(message)

Resources