From: Νίκος on
Hello guys! Need your precious help again!

In every html file i have in the very first line a page_id fro counetr
countign purpsoes like in a format of a comment like this:

<!-- 1 -->
<!-- 2 -->
<!-- 3 -->

and so on. every html file has its one page_id

How can i grab that string representaion of a number from inside
the .html file using regex and convert it to an integer value?

# ==============================
# open current html template and get the page ID number
# ==============================

f = open( '/home/webville/public_html/' + page )

#read first line of the file
firstline = f.readline()

page_id = re.match( '<!-- \d -->', firstline )
print ( page_id )
From: Νίκος on
i also dont know what wrong with this line:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]

hostmatch = re.search('cyta', host)

if cookie.has_key('visitor') != 'nikos' or hostmatch is None:
# do stuff

the 'stuff' never gets executed, while i ant them to be as long as i
dont have regex match!
From: MRAB on
Νίκος wrote:
> Hello guys! Need your precious help again!
>
> In every html file i have in the very first line a page_id fro counetr
> countign purpsoes like in a format of a comment like this:
>
> <!-- 1 -->
> <!-- 2 -->
> <!-- 3 -->
>
> and so on. every html file has its one page_id
>
> How can i grab that string representaion of a number from inside
> the .html file using regex and convert it to an integer value?
>
> # ==============================
> # open current html template and get the page ID number
> # ==============================
>
> f = open( '/home/webville/public_html/' + page )
>
> #read first line of the file
> firstline = f.readline()
>
> page_id = re.match( '<!-- \d -->', firstline )
> print ( page_id )

Use group capture:

found = re.match(r'<!-- (\d+) -->', firstline).group(1)
print(page_id)
From: MRAB on
Νίκος wrote:
> i also dont know what wrong with this line:
>
> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>
> hostmatch = re.search('cyta', host)
>
> if cookie.has_key('visitor') != 'nikos' or hostmatch is None:
> # do stuff
>
> the 'stuff' never gets executed, while i ant them to be as long as i
> dont have regex match!

Try printing out repr(host). Does it contain "cyta"?
From: Νίκος on
On 7 Αύγ, 21:27, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
> Νίκος wrote:
> > i also dont know what wrong with this line:
>
> > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>
> > hostmatch = re.search('cyta', host)
>
> > if cookie.has_key('visitor') != 'nikos' or hostmatch is None:
> >      # do stuff
>
> > the 'stuff' never gets executed, while i want them to be as long as i
> > dont have regex match!
>
> Try printing out repr(host). Does it contain "cyta"?

Yes it does contain it as print shown!

is something wrong with this line in logic or syntax?

if cookie.has_key('visitor') != 'nikos' or re.search('cyta', host) is
None:
# do database stuff