dmeekins / callblock

Python junk call blocker based off jcblock.
GNU General Public License v3.0
3 stars 1 forks source link

callblock.py execution error... please help!:) #1

Open nmr50 opened 4 years ago

nmr50 commented 4 years ago
[2019-10-01][14:30]{tmh@r50}[91] ~/callblock>cat callblock.conf
Device = /dev/ttyACM*
Log = /home/tmh/callblock/callblock.log
PIDFile = /home/tmh/callblock/callblock.pid

[Blacklist]
Numbers =
89160000000
[2019-10-01][14:32]{tmh@r50}[92] ~/callblock>sudo ./callblock.py -c callblock.conf
Traceback (most recent call last):
  File "./callblock.py", line 373, in <module>
    main()
  File "./callblock.py", line 300, in main
    config.read(configfile)
  File "/usr/lib/python3.4/configparser.py", line 672, in read
    self._read(fp, filename)
  File "/usr/lib/python3.4/configparser.py", line 1088, in _read
    raise e
configparser.ParsingError: Source contains parsing errors: 'callblock.conf'
        [line  8]: '89160000000\n'

Please explain, what should I do to run this .py script. Thanks in advance ! -t ps. I use USR5637 USB modem, and this is how its FSK caller ID ft is working with incoming ring: RING

DATE=1001 TIME=1434 NMBR=89160000000 (zeroes are placed for privacy purpose:)

dmeekins commented 4 years ago

What does your full config look like? There's an error in its format somewhere, so the config parser ran into something unexpected.

On Tue, Oct 1, 2019, 07:31 nmr50 notifications@github.com wrote:

[2019-10-01][14:28]/callblock>cat callblock.conf [General] Device = /dev/ttyACM* Log = /home/tmh/callblock/callblock.log PIDFile = /home/tmh/callblock/callblock.pid [Blacklist] Numbers = 89161234567 [2019-10-01][14:28]/callblock>sudo ./callblock.py -c callblock.conf Traceback (most recent call last): File "./callblock.py", line 373, in main() File "./callblock.py", line 300, in main config.read(configfile) File "/usr/lib/python3.4/configparser.py", line 672, in read self._read(fp, filename) File "/usr/lib/python3.4/configparser.py", line 1088, in _read raise e configparser.ParsingError: Source contains parsing errors: 'callblock.conf'

Please explain, what should I do to run this .py script. Thanks in advance ! -t

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dmeekins/callblock/issues/1?email_source=notifications&email_token=ACXLWU6RGI4XGL7WWGVF6OLQMMYJLA5CNFSM4I4IHBBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HO2ES6A, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXLWU2J2MZOXSZK4HFAWMLQMMYJLANCNFSM4I4IHBBA .

nmr50 commented 4 years ago

I posted 'cat callblock.conf' earlier, let me paste it again: * [General] Device = /dev/ttyACM Log = /home/tmh/callblock/callblock.log PIDFile = /home/tmh/callblock/callblock.pid

[Blacklist] Numbers = 89160000000 * As you see I removed "names" strings so numbers strings are left only. I also tried to remove "8" from this 10-digits number, but got no luck... I even replaced ttyACM with ttyACM0 - according device name I have.. no luck. ps. btw, can I just use callblock.log and callblock.pid files w/o path names to those ?

nmr50 commented 4 years ago

Heck, I just add TWO SPACES before number 8916... and program did run OK! Man, I cannot give no advises to you, but I think it is very small problem that could be solved ASAP !:)

--- Now I see that program ran ok: tail -f callblock.log 2019-10-01 15:06:15 - callblock[3093] - INFO:opened device /dev/ttyACM0 2019-10-01 15:06:15 - callblock[3093] - INFO:callblock started but - when I do call - I see no blocking result ! should I use 9 digits in Numbers section instead of 10 ones, please explain ? It is strange, because default callblock.conf has 10 digits example numbers, commented out.

dmeekins commented 4 years ago

Good catch. I forgot multi-line values need to be indented. According to the Python docs: "Values can also span multiple lines, as long as they are indented deeper than the first line of the value." ( https://docs.python.org/3/library/configparser.html)

I can update my documentation to make that more clear.

On Tue, Oct 1, 2019, 08:07 nmr50 notifications@github.com wrote:

Heck, I just add TWO SPACED before number 8916... and program did run OK! Man, I cannot give no advices, but I think it very simple problem that could be solved!:)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dmeekins/callblock/issues/1?email_source=notifications&email_token=ACXLWUZEVMHER4BIFZXUDVLQMM4OJA5CNFSM4I4IHBBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEABA3QI#issuecomment-537005505, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXLWUYXGKT6JSF4CBMJ2TTQMM4OJANCNFSM4I4IHBBA .

nmr50 commented 4 years ago

More investigation is on the way ! Config is here: * [General] Device = /dev/ttyACM Log = /home/tmh/callblock/callblock.log PIDFile = /home/tmh/callblock/callblock.pid

[Blacklist] Numbers = 89160000000 The program is running as fork, ok! But when I do the call from that private number, I get this! sudo ./callblock.py -c callblock.conf -f 2019-10-01 15:14:46 - callblock[3134] - INFO:opened device /dev/ttyACM0 2019-10-01 15:14:46 - callblock[3134] - INFO:callblock started Traceback (most recent call last): File "./callblock.py", line 373, in main() File "./callblock.py", line 364, in main call_loop(modem, blacklist) File "./callblock.py", line 212, in call_loop call = modem.wait_for_call() File "./callblock.py", line 156, in wait_for_call key, val = part.split(' = ') ValueError: need more than 1 value to unpack **

Any ideas ? Might be your script is sharpened to work with another caller ID stuff from another modem, not USR one ? ps. heck, this STRANGE github editor removes those TWO SPACES from config file I posted in this message..

dmeekins commented 4 years ago

Try editing the source code and replace split(" = ") with split("=") on line 156 (remove the space around the equals sign). There might need to be a few other changes to support your modem's format.

On Tue, Oct 1, 2019, 08:16 nmr50 notifications@github.com wrote:

More investigation is on the way ! Config is here:

[General] Device = /dev/ttyACM* Log = /home/tmh/callblock/callblock.log PIDFile = /home/tmh/callblock/callblock.pid

[Blacklist] Numbers = 89160000000

The program is running as fork, ok! But when I do the call from that private number, I get this!

sudo ./callblock.py -c callblock.conf -f 2019-10-01 15:14:46 - callblock[3134] - INFO:opened device /dev/ttyACM0 2019-10-01 15:14:46 - callblock[3134] - INFO:callblock started Traceback (most recent call last): File "./callblock.py", line 373, in main() File "./callblock.py", line 364, in main call_loop(modem, blacklist) File "./callblock.py", line 212, in call_loop call = modem.wait_for_call() File "./callblock.py", line 156, in wait_for_call key, val = part.split(' = ') ValueError: need more than 1 value to unpack

Is that "Names" field mandatory to be placed in callblock.conf? lemme check!:)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dmeekins/callblock/issues/1?email_source=notifications&email_token=ACXLWU6OCKEZUZV36PHMXYDQMM5SRA5CNFSM4I4IHBBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEABBVKY#issuecomment-537008811, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXLWU6RDPGWVQGRAUQC5SLQMM5SRANCNFSM4I4IHBBA .

nmr50 commented 4 years ago

OK, that error has gone, but I got another one!:) sudo ./callblock.py -c callblock.conf -f 2019-10-01 15:25:26 - callblock[3158] - INFO:opened device /dev/ttyACM0 2019-10-01 15:25:26 - callblock[3158] - INFO:callblock started Traceback (most recent call last): File "./callblock.py", line 373, in main() File "./callblock.py", line 364, in main call_loop(modem, blacklist) File "./callblock.py", line 212, in call_loop call = modem.wait_for_call() File "./callblock.py", line 162, in wait_forcall return Call(dt, dict['NMBR'], dict_['NAME']) KeyError: 'NAME'

nmr50 commented 4 years ago

BTW, I want to ask you to improve this script with a small feature.. Can you add callednumbers.log into the script - separate off main callblock.log - yet with no overwriting but adding new lines to it - so I can see what numbers have called to me ? Useful feature!:)

I will repeat the strings from USR5637 caller ID routine: RING

DATE=1001 TIME=1434 NMBR=89160000000

This is the way to solve routine in your .py script how to parse strings, at first. At second I think these DATE and TIME strings useful either to insert their info into callednumbers.log like this: 2019-10-01 14:34 89160000000 -- something like that :) PS. might be specifying modem type in .conf file - MODEMTYPE=USR5637 will use different parsing code... and MODEMTYPE=yourmodem.you've.used will use original parsing code ?

nmr50 commented 4 years ago

AHA! I found the stuff, and its seems it solves the problem with my modem that has NO 'name' string:

            return Call(dt, dict_['NMBR'])
            #, dict_['NAME'])

-- as you see I commented out 'NAME' stuff from the .py script, and script started to work NICELY ! Here is the log:

2019-10-01 15:40:15 - callblock[3176] - INFO:received call: date=2019-10-01T15:40:00, number=89160000000, name=
2019-10-01 15:40:15 - callblock[3176] - INFO:blocking call from 89160000000/

-- I want to make further cosmetic changes - to remove "T" between date and time, to remove seconds from time (because modem is not using "seconds", so script pasting 00 all the time). Another thingie - this slash after number... should be removed, either !:) and ", name=' also should be removed - in my case, of course.

btw, if you won't mess up with coding callednumbers.log file, can you tell me how to prevent callblock.log being emptied every time script is restarted ?

nmr50 commented 4 years ago

OK, I removed slash, and (almost:) all names in logging stuff, yet in detecting stuff earlier, the log is looks like this now:

2019-10-01 16:25:06 - callblock[3213] - INFO:received call: date=2019-10-01T16:25:00, number=89160000000
2019-10-01 16:25:06 - callblock[3213] - INFO:blocking call from 89160000000

The three questions are left: 1) How to remove "T" between date and time ? 2) How to get rid of seconds in seconds, right time field ? 3) How to stop overwriting callblock.log file upon script starting ?

I attached altered .py script edited by me with diffs file, please take a look if you please :) callblock.ALT.py.txt cb.diffs.txt I will be waiting for the answers on those qs - thank in advance !:)

nmr50 commented 4 years ago

Another ideas I got: do we need that 'received call' string at all ? Might be it will be enough to have just one string "blocking received call NUMBER from black list" - so we will get rid of 1st and 2nd questions in one time ?

Why I am asking - we already have DATE and TIME values in log at left side, so we surely don't need to repeat those date and time values again, yet with "T" inside and not needed seconds...

Second one... Do we really need "- callblock[PID] -" in log file? Can it be replaced with "Running callblock.py with PID" at once instead of repeating script name and its PID in every log string ?

Tell me, what you think about it ? :) Yes, the log also be shorter without that string!:)

nmr50 commented 4 years ago

Strange thing I met - I found that script clears some records from the log file for reason I don't understand. Look here, please:

[2019-10-01][16:48] ~/callblock>tail -f callblock.log 
2019-10-01 15:06:15 - callblock[3093] - INFO:opened device /dev/ttyACM0
2019-10-01 15:06:15 - callblock[3093] - INFO:callblock started
2019-10-01 16:49:07 - callblock[3213] - INFO:received call: date=2019-10-01T16:49:00, number=891600000000
2019-10-01 16:49:07 - callblock[3213] - INFO:blocking call from 891600000000
2019-10-01 16:49:28 - callblock[3213] - INFO:received call: date=2019-10-01T16:49:00, number=891600000000
2019-10-01 16:49:28 - callblock[3213] - INFO:blocking call from 89160000000
^C
[2019-10-01][17:37]~/callblock>tail -f callblock.log
2019-10-01 15:06:15 - callblock[3093] - INFO:opened device /dev/ttyACM0
2019-10-01 15:06:15 - callblock[3093] - INFO:callblock started
^C
[2019-10-01][17:38] ~/callblock>tail -f callblock.log -n 500
2019-10-01 15:06:15 - callblock[3093] - INFO:opened device /dev/ttyACM0
2019-10-01 15:06:15 - callblock[3093] - INFO:callblock started
^C
[2019-10-01][17:38] ~/callblock>
nmr50 commented 4 years ago

OK, what I got in result: 2019-10-01 20:11:52 - opened device /dev/ttyACM0 2019-10-01 20:11:52 - callblock started 2019-10-01 20:12:08 - blocking received blacklisted call 89160000000 but still I cannot understand how the logging stuff is working - I see messages in stdout when I run the script, but I do not see incoming calls in log file... the running script -f >gotnumbers gives NOTHING - python does not nothing on redirecting the stuff from console to my own log file....

Do you have idea how to dump all the stuff into logfile ASAP, and do not empty or cut it in anyway ?

dmeekins commented 4 years ago

I can work on making the data parsing more flexible for different types of modems. Thanks for letting me know about the different format you get.

Feel free to change how it logs to your taste. I probably won't change the format in the committed code because I have it to my liking. I prefer a single log file, and can just grep specific types of lines when needed. Even though the datetime stamp is included when logged, I also include the date/time that is given in the caller ID data because I like to have that additional information in case it's different.

I'm not sure how your log file is getting emptied when restarting. The Python logging module should be appending to the file whenever opening it. I've had the same file since 2015 and it never got truncated after any restarts. Check out the documentation for the "logging" and "logging.config" modules on ways you can troubleshoot your logging issue.

On Tue, Oct 1, 2019 at 1:15 PM nmr50 notifications@github.com wrote:

OK, what I got in result: 2019-10-01 20:11:52 - opened device /dev/ttyACM0 2019-10-01 20:11:52 - callblock started 2019-10-01 20:12:08 - blocking received blacklisted call 89160000000 but still I cannot understand how the logging stuff is working - I see stdout when I run the script, but I do not see incoming calls in log file... the running script -f >gotnumbers gives NOTHING - python does not nothing to give out with redirect the stuff from console to my own log file....

Do you have idea how to dump all the stuff into logfile ASAP, and do not empty or cut it in anyway ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dmeekins/callblock/issues/1?email_source=notifications&email_token=ACXLWUZ2F3EGRLRW7WZKTZ3QMOATHA5CNFSM4I4IHBBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEACA42Y#issuecomment-537136747, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXLWU3JJ5IUG6OJQSFT2ZDQMOATHANCNFSM4I4IHBBA .

nmr50 commented 4 years ago

Please watch this small video video (online viewing is available) I made for you - https://yadi.sk/d/Vl9N3RcwBuAPFg with logging into stdout and empty callblock.log, while settings are: [General] Device = /dev/ttyACM* Log = callblock.log PIDFile = callblock.pid ... and numbers in the list.

nmr50 commented 4 years ago

One thing I want to ask besides main question about logging: Tell please - is it possible to add wildcards in numbers list like to have an array of numbers of such kind: 89169* (89169000000-89169999999), 8916911?2222 (891691102222, 891691112222, 891691132222 etc) ?

Or, to step aside of classical wildcards, and to use CSV-alike mode instead: 495;1210000;1211999 - it is citycode:startnumber:endnumber array 495;2250100;2250141 - the same, 4952250100 to 4952250141 array I'll add leading '8' by myself, if we you'll add this CSV code :) What will you tell ?:)

dmeekins commented 4 years ago

The wildcard feature isn't currently available, but I could add it in.

On Fri, Oct 4, 2019 at 1:04 PM nmr50 notifications@github.com wrote:

One thing I want to ask besides main question about logging: Tell please - is it possible to add wildcards in numbers list like to have an array of numbers of such kind: 89169* (89169000000000-89169999999999), 8916911?2222 (891691102222, 891691112222, 891691132222 etc) ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dmeekins/callblock/issues/1?email_source=notifications&email_token=ACXLWU77YPM5HEFLN4XL7ATQM5ZP7A5CNFSM4I4IHBBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAMJB2Q#issuecomment-538480874, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXLWUYJMREP3LJWASZVJM3QM5ZP7ANCNFSM4I4IHBBA .

nmr50 commented 4 years ago

I think the parsing will be easy for both of them, if its possible, of course, to grep "*" and "?" without presence ";" symbols in the string, or vice versa - no wildcards symbols, but at least two ";" symbols in the string. Something like that:)

nmr50 commented 4 years ago

BTW, I've had a talk to local pythonians, they've nicely explained to me that your script has "-f" flag that causes log the output to console only while script is running in foreground, yet running script w/o "-f" flag will log stuff into the mentioned logfile... but in background, no console output. Ppl I meant gave me this url: http://www.blog.pythonlibrary.org/2013/07/18/python-logging-how-to-log-to-multiple-locations/ but I asked 'em to make these changes to the script... I'll report by results (if I'll be faster than you!:).

UPDATE: I replaced stderr with stdout in logging section of script, and now I use this one: sudo ./callblock.py -c callblock.conf -f | tee -a callblock.log (with chmod a+w callblock.log from root, of course) -- now I see console output AND I see logging to callblock.log at the same time :) JFYI

nmr50 commented 4 years ago

Hello ! Any news about wildcards in blacklist numbers or/and semicolon format of blacklist numbers?:)

I thought about another thingie... Since I received hundreds of spammers' calls in these years, I found that some operators works only with legal orgs only - not with usual persons - so I wanted to block those operators by blacklisting ALL of their numbers. Please, tell me, is it possible to have function to INCLUDE blacklist files into callblock.conf ? I mean - if I want to block WHOLE numbers array of some spam operator, I'd paste those numbers into another file named spamoperator1.list, and then include this file into callblock.conf like in usual config - include = spamoperator1.list, for example. Of course, the count of numbers might be reduced by implementing that wildcards or semicolon format feature..

nmr50 commented 4 years ago

Btw, buddies of mine concluded, that wildcards are not effective in this case: 495;2250150;2250235;86 -- because in result I'll get about 8 strings instead of this one, so better use this CSV format at all:) files inclusion is needed also...