Script stops running with no error

2024-08-28 Thread Daniel via Python-list
As you all have seen on my intro post, I am in a project using Python
(which I'm learning as I go) using the wikimedia API to pull data from
wiktionary.org. I want to parse the json and output, for now, just the
definition of the word.

Wiktionary is wikimedia's dictionary.

My requirements for v1

Query the api for the definition for table (in the python script).
Pull the proper json
Parse the json
output the definition only

What's happening?

I run the script and, maybe I don't know shit from shinola, but it
appears I composed it properly. I wrote the script to do the above.
The wiktionary json file denotes a list with this character # and
sublists as ## but numbers them

On Wiktionary, the definitions are denoted like:

1. blablabla
1. blablabla
2. blablablablabla
2. balbalbla
3. blablabla
   1. blablabla


I wrote my script to alter it so that the sublist are letters

1. blablabla
   a. blablabla
   b. blablabla
2. blablabla and so on
/snip

At this point, the script stops after it assesses the first line_counter
and sub_counter. The code is below, please tell me which stupid mistake
I made (I'm sure it's simple).

Am I making a bad approach? Is there an easier method of parsing json
than the way I'm doing it? I'm all ears.

Be kind, i'm really new at python. Environment is emacs.

import requests
import re

search_url = 'https://api.wikimedia.org/core/v1/wiktionary/en/search/page'
search_query = 'table'
parameters = {'q': search_query}

response = requests.get(search_url, params=parameters)
data = response.json()

page_id = None

if 'pages' in data:
for page in data['pages']:
title = page.get('title', '').lower()
if title == search_query.lower():
page_id = page.get('id')
break

if page_id:
content_url =
f'https://api.wikimedia.org/core/v1/wiktionary/en/page/
{search_query}'
response = requests.get(content_url)
page_data = response.json()
if 'source' in page_data:
content = page_data['source']
cases = {'noun': r'\{en-noun\}(.*?)(?=\{|\Z)',
 'verb': r'\{en-verb\}(.*?)(?=\{|\Z)',
 'adjective': r'\{en-adj\}(.*?)(?=\{|\Z)',
 'adverb': r'\{en-adv\}(.*?)(?=\{|\Z)',
 'preposition': r'\{en-prep\}(.*?)(?=\{|\Z)',
 'conjunction': r'\{en-con\}(.*?)(?=\{|\Z)',
 'interjection': r'\{en-intj\}(.*?)(?=\{|\Z)',
 'determiner': r'\{en-det\}(.*?)(?=\{|\Z)',
 'pronoun': r'\{en-pron\}(.*?)(?=\{|\Z)'
 #make sure there aren't more word types
}

def clean_definition(text):
text = re.sub(r'\[\[(.*?)\]\]', r'\1', text)
text = text.lstrip('#').strip()
return text

print(f"\n*** Definition for {search_query} ***")
for word_type, pattern in cases.items():
match = re.search(pattern, content, re.DOTALL)
if match:
lines = [line.strip() for line in
match.group(1).split('\n')
if line.strip()]
definition = []
main_counter = 0
sub_counter = 'a'

for line in lines:
if line.startswith('##*') or line.startswith('##:'):
continue

if line.startswith('# ') or line.startswith('#\t'):
main_counter += 1
sub_counter = 'a'
cleaned_line = clean_definition(line)
definition.append(f"{main_counter}. {cleaned_line}")
elif line.startswith('##'):
cleaned_line = clean_definition(line)
definition.append(f"   {sub_counter}. {cleaned_line}")
sub_counter = chr(ord(sub_counter) + 1)

if definition:
print(f"\n{word_type.capitalize()}\n")
print("\n".join(definition))
break
else:
print("try again beotch")

Thanks,

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new here

2024-08-28 Thread Daniel via Python-list
rbowman  writes:

> On Sun, 25 Aug 2024 21:29:30 -0400, avi.e.gross wrote:
>
>> If everyone will pardon my curiosity, who and what purposes are these
>> smaller environments for and do many people use them?
>> 
>> I mean the price of a typical minimal laptop is not a big deal today. So
>> are these for some sort of embedded uses?
>> 
>> I read about them ages ago but wonder ...
>
> Typically they are used for I/O with the physical world. Some, like the 
> Arduino Nano Sense, have a number of sensors on the board including a 9 
> axis inertial, temperature, humidity, barometric, microphone, light 
> intensity, and color sensors. MIT chose this for their TinyML course 
> because it was one-stop shopping. Using TinyML, a really cut down version 
> of TensorFlow, gesture, wake word, image recognition, and other tasks were 
> move entirely to the edge device.
>
> Others, like the Pico series, bring out the I/O pins but have little 
> onboard. Many pins are multi-purpose and are used for SPI or I2C 
> protocols, PWM, A/D measurements, and plain vanilla digital.
>
> The Raspberry Pi series lives in both worlds. Particularly with the new Pi 
> 5, it's usable as a desktop Linux system, if somewhat limited, while 
> bringing out the PIO pins. 
>
> It's really a different world than a typical laptop. Years (decades?) ago 
> you could subvert the parallel port controller to provide digital I/O but 
> who has seen a parallel port lately? 
>
> There are many families and devices available that are used for any number 
> of projects that need to interact with the real world. The earliest 
> variants were usually programmed in assembler since 2k of EPROM and 128 
> bytes of RAM was typical.  As they improved C was sued. Now there's enough 
> flash and SRAM to support MicroPython or CircuitPython and they are fast 
> enough for most purposes. There are specialized drivers but if you know 
> Python the bulk of the logic will be very familiar. 
>
> For example I have a desktop Python app that pulls weather data from 
> NOAA's web API.  The Pico W has Wifi, so if I wanted to compare NOAA's 
> temperature, humidity, and barometric pressure to the values I read from a 
> local sensor, the API requests and parsing the JSON reply would be almost 
> identical to the desktop code.  Conversely I could use the Pico W as a web 
> server to make its sensor reading available. 

That is so cool. I've had the same idea to use the API with AWS for my
bbs. I also want to do the same thing for other government sites like
ecfr for pulling aviation regulations.

Is your code somewhere I can look at it?

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new here

2024-08-22 Thread Daniel via Python-list
Jason Friedman  writes:

> On Wed, Aug 21, 2024 at 4:04 PM Daniel via Python-list <
> python-list@python.org> wrote:
>
>>
>> An example of use, here's a weather service tied to a finger. Put your
>> city name as the user. This isn't mine, but it is inspiring. Example:
>>
>> finger mi...@graph.no
>>
>> For all options, go to the help finger:
>>
>> finger h...@graph.no
>
>
> Quite cool!

Right? It's so quick too. Just thinking how broad you can make it -
accessing live data on the internet without the need of a broadband
connection.

If you want to check out the fingerverse

finger fingerve...@happynetbox.com

If you remember webrings, there's a finger ring, though there aren't
alot of fingers registered on there yet. 

finger r...@thebackupbox.net

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new here

2024-08-22 Thread Daniel via Python-list
rbowman  writes:

> On Wed, 21 Aug 2024 22:15:37 +0100, Daniel wrote:
>
>> Lesser used protocols not known by many in the mainstream. Such as:
>> 
>> gopher, gemini, finger, spartan, titan, etc.
>> 
>> An example of use, here's a weather service tied to a finger. Put your
>> city name as the user. This isn't mine, but it is inspiring. Example:
>> 
>> finger mi...@graph.no
>> 
>> For all options, go to the help finger:
>> 
>> finger h...@graph.no
>
> Thanks. Interesting. I was surprised a Norwegian site would have data for 
> a small city in the US. I have a Python script that accesses the NOAA 
> (National Oceanic and Atmospheric Administration) API and the data in the 
> Meteogram appears to match well. fwiw, all that does is
>
>observation_url = f"https://api.weather.gov/stations/K{grid_id}/
> observations/latest"
> response = requests.get(observation_url).json()

I think he uses a weather service API to call the data, and I'm sure
they all share data across other national weather services. That's just
a guess. 

>
> using the Python 'requests' package and then parsing out the JSON.  
> Implementing finger probably would be a straight socket connection. I 
> don't know how useful this is: 
>
> https://pypi.org/project/pyfinger/
>
> I assume gopher is fron the archie, veronica, and jughead days. It appears 
> straightforward.

I use gopher all the time, and the lynx browser supports it directly.

If you have lynx, you can visit this gopher interface to Wikipedia:

gopher://gopherpedia.com

If you like Reddit, there's this

gopher://gopherddit.com

Of course it's read only, but if you're wishing to leisurely read posts
on reddit in a super fast gopher page, you can.

Right now, I'm focused on providing wiktionary.org services on gopher as
well as finger.

These are longterm projects since I can only learn python and code on
spare time, which I have little.

/snip

I will be posting my coding questions in here.

Thanks guys.

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new here

2024-08-21 Thread Daniel via Python-list
rbowman  writes:

> On Tue, 20 Aug 2024 23:26:39 +0100, Daniel wrote:
>
>> New here. I've perused some posts and haven't seen a posting FAQ for
>> this NG. I'm learning python right now to realize some hobby goals I
>> have regarding some smolnet services. What are the NG standards on
>> pasting code in messages? Do yall prefer I post a pastebin link if it's
>> over a certain number of lines? I know this isn't IRC - just asking.
>
> 
> Standards? This is usenet, the last remaining wild west. Good news: c.l.p 
> isn't overrun by trolls.  Bad news: c.l.p doesn't seem to be overrun by 
> much of anybody.
> 

I'm not worried much about large populations. i've been on massive
forums and had less results than I did with an IRC channel with four
users. 

>
> smolnet, as in things like 

Lesser used protocols not known by many in the mainstream. Such as:

gopher, gemini, finger, spartan, titan, etc.

An example of use, here's a weather service tied to a finger. Put your
city name as the user. This isn't mine, but it is inspiring. Example:

finger mi...@graph.no

For all options, go to the help finger:

finger h...@graph.no

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new here

2024-08-21 Thread Daniel via Python-list
dn  writes:

> On 21/08/24 10:26, Daniel via Python-list wrote:
>> Hi folks -
>> New here. I've perused some posts and haven't seen a posting FAQ for
>> this NG. I'm learning python right now to realize some hobby goals I
>> have regarding some smolnet services. What are the NG standards on
>> pasting code in messages? Do yall prefer I post a pastebin link if it's
>> over a certain number of lines? I know this isn't IRC - just asking.
>
>
> Welcome Daniel!
>
> Despite some seeming to think of sending you elsewhere, there are a
> number of people 'here' who regularly volunteer their time to help
> others.
>
> As with any interaction, the quality of information in the question
> directly impacts what can be offered in-response.
>
> More of us can help with (pure) Python questions. Moving into
> specialised areas may reduce the number who feel competent to answer.
>
> We'll value any contribution you may be able to offer, and will look
> forward to hearing of the projects you attempt...

Thanks man. Yeah I'm not going anywhere. If I don't get good answers
from here then I'll go to IRC.

I am on forums but tend to stay away from them unless I absolutely have
to. I like newsgroups as they are - though I have noticed a massive drop
in users ever since Google dropped their groups service. I also saw a
minor drop in spam.

I'm not too worried about the trolls either.

D
-- 
https://mail.python.org/mailman/listinfo/python-list


new here

2024-08-20 Thread Daniel via Python-list
Hi folks -

New here. I've perused some posts and haven't seen a posting FAQ for
this NG. I'm learning python right now to realize some hobby goals I
have regarding some smolnet services. What are the NG standards on
pasting code in messages? Do yall prefer I post a pastebin link if it's
over a certain number of lines? I know this isn't IRC - just asking.

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for irc client

2024-07-04 Thread Daniel via Python-list
inhahe  writes:

> On Thu, Jul 4, 2024 at 5:14 AM Daniel via Python-list <
> python-list@python.org> wrote:
>
>> Hi guys -
>>
>> I have historical experience developing sofwtare for my own use. It has
>> been
>> quite a while since doing so and the advent of new languages has brought me
>> here. Python has built quite a reputation. It would be fun to pick up a
>> new language while I'm at it.
>>
>> I've been a consumer of IRC since the nineties and have been running an
>> instance of quassel core on an old laptop for the last decade. Over the
>> years, my use of xwindows has dramatically decreased and I spend 90% of my
>> computer time with multiple panes of tmux while I do my usual daily fun.
>> One
>> thing missing is a good textmode irc client that will connect to quassel
>> core.
>>
>> I've seen efforts to make a plugin for weechat but, to date, I don't see
>> much
>> progress on that end.
>>
>> In your wisdom, would python be a good environment to accomplish this? I'd
>> likely use extended ascii and colors. The point would be to minimize the
>> memory footprint of the application.
>>
>> I don't use standard desktop computers anymore - I'm writing this on my
>> beloved pi400 using emacs.
>>
>> Thanks
>>
>> Daniel
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> I think Python would be a great language to write an IRC client in, it's a
> rapid-development language, and also Python is particularly good for text
> manipulation and the IRC protocol is textual rather than binary. But, if
> your only purpose for using Python is to reduce the memory footprint, I'm
> not sure. I don't know specifically, but I'd guess Python has a higher
> memory footprint than, say, C, because it's a high-level language. For
> example, each variable has to be boxed, and also the interpreter has to be
> loaded..
>
> Regarding high ASCII, I don't know if that works in IRC, but either way,
> ASCII isn't really enough nowadays. You need to support Unicode;
> specifically, UTF-8.

Okay great. Since my original post, I settled on UTF8. I have to create
a list of requirements for v1.0 to limit scope creep and I can actually
get this done.

I may put it on github and solicit for assistance at some point.

Thanks for the response, both of them. I'll look at the other code and
see how I can fold it in. What I have to find out, still, is how the
core server manages the messages. I suspect the core does all the
sending and receiving and the client just sends the packets to core for
management. That's just a guess though.

I still have to review the liraries, this is a new idea hatched last
night so I have yet to investigate much.

My initial thought was C++ but this would be my first termianl-only
application in many years so I thought a different coding platform would
be effective.

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list


python for irc client

2024-07-04 Thread Daniel via Python-list
Hi guys -

I have historical experience developing sofwtare for my own use. It has been
quite a while since doing so and the advent of new languages has brought me
here. Python has built quite a reputation. It would be fun to pick up a
new language while I'm at it.

I've been a consumer of IRC since the nineties and have been running an
instance of quassel core on an old laptop for the last decade. Over the
years, my use of xwindows has dramatically decreased and I spend 90% of my
computer time with multiple panes of tmux while I do my usual daily fun. One
thing missing is a good textmode irc client that will connect to quassel
core.

I've seen efforts to make a plugin for weechat but, to date, I don't see much
progress on that end.

In your wisdom, would python be a good environment to accomplish this? I'd
likely use extended ascii and colors. The point would be to minimize the
memory footprint of the application.

I don't use standard desktop computers anymore - I'm writing this on my
beloved pi400 using emacs.

Thanks

Daniel
-- 
https://mail.python.org/mailman/listinfo/python-list