Global scope not being set
I'm working on a plugin for MyBB and for some reason, it seems PHP is not
setting global scope to some of my variables.
I have the following code in my plugin file:
$mod_template = 'member_login';
$search_string = '{$footer}';
$replace_string = 'hello';
function myplugin_activate()
{
global $mod_template, $search_string, $replace_string;
$data = "_activate()\n";
$data .= '$local_var = '.$local_var."\n";
$data .= '$mod_template = '.$mod_template."\n";
$data .= '$search_string = '.$search_string."\n";
$data .= '$replace_string = '.$replace_string."\n";
$data .= 'line1: #'.preg_quote($search_string).'#i'."\n";
$data .= 'line2: #'.preg_quote($replace_string).'#i';
file_put_contents('/tmp/log1.txt', $data);
}
function myplugin_deactivate()
{
global $mod_template, $search_string, $replace_string;
$data = "_deactivate()\n";
$data .= '$local_var = '.$local_var."\n";
$data .= '$mod_template = '.$mod_template."\n";
$data .= '$search_string = '.$search_string."\n";
$data .= '$replace_string = '.$replace_string."\n";
$data .= 'line1: #'.preg_quote($search_string).'#i'."\n";
$data .= 'line2: #'.preg_quote($replace_string).'#i';
file_put_contents('/tmp/log2.txt', $data);
}
The code is the same for the body of both functions (except of course for
the name of the file and the title placed inside the file).
When I activate and deactivate my plugin, the two log files are generated
and I get the following:
log1.txt
_activate()
$local_var = testing
$mod_template = member_login
$search_string = {$footer}
$replace_string = hello
line1: #\{\$footer\}#i
line2: #hello#i
log2.txt
_deactivate()
$local_var = testing
$mod_template =
$search_string =
$replace_string =
line1: ##i
line2: ##i
So, in the myplugin_deactivate() function, the global scope is not being
set for some reason.
Butkovich
Sunday, 1 September 2013
Find all the contents between two tags in python
Find all the contents between two tags in python
<p>This is the first paragraph with some details</p>
<p><a href = "user1">This contains name of the user1</a>
<p><font>This is the contents from user1</font></p>
<p><a href = "user2">This contains name of the user2</a>
<p><font>This is the contents from user2</font></p>
This is the structure of my html. My aim is to extract the users and their
contents. In this case it should print all the contents between two 'a'
tags
The code which i tried is :
for i in soup.findAll('a'):
while(i.nextSibling.name!='a'):
print i.nextSibling
I returns me an infinite loop. So if anyone has idea how i can solve this
issue please share it with me.
<p>This is the first paragraph with some details</p>
<p><a href = "user1">This contains name of the user1</a>
<p><font>This is the contents from user1</font></p>
<p><a href = "user2">This contains name of the user2</a>
<p><font>This is the contents from user2</font></p>
This is the structure of my html. My aim is to extract the users and their
contents. In this case it should print all the contents between two 'a'
tags
The code which i tried is :
for i in soup.findAll('a'):
while(i.nextSibling.name!='a'):
print i.nextSibling
I returns me an infinite loop. So if anyone has idea how i can solve this
issue please share it with me.
How to make a relationship between 2 id objects ? 1 id object say get videos then play 1 by 1
How to make a relationship between 2 id objects ? 1 id object say get
videos then play 1 by 1
I would like to know how to make a "connection" between 2 id objects. 1
«cadre» (box) of drag and drop video list and a I would like make like
this : Canvas get videos of cadre2 then play those 1 by 1 in order in
canvas and actualize the list when it has drops and replay list after the
last video. I've put the videos in cadre2 in a list like
Hope someone can help me out!! Thanks so much in advance!!
videos then play 1 by 1
I would like to know how to make a "connection" between 2 id objects. 1
«cadre» (box) of drag and drop video list and a I would like make like
this : Canvas get videos of cadre2 then play those 1 by 1 in order in
canvas and actualize the list when it has drops and replay list after the
last video. I've put the videos in cadre2 in a list like
Hope someone can help me out!! Thanks so much in advance!!
Saturday, 31 August 2013
python consecutive urllib2 POST gives 404
python consecutive urllib2 POST gives 404
The problem that I have - and try to solve with Python - is to make
consecutive POST requests (completing an online form) for a website
(specifically, a free online demo of an api at
demo.travelportuniversalapi.com). I am not able to acquire the results
page so far - been at this for two days now.
The code I employ is:
import sys
import urllib, urllib2, cookielib
from BeautifulSoup import BeautifulSoup
import re
class website:
def __init__(self):
self.host = 'demo.travelportuniversalapi.com'
self.ua = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0)
Gecko/20100101 Firefox/23.0'
self.session = cookielib.CookieJar() #session devine o
instanta a obiectului cookielib
pass
def get(self):
try:
url =
'http://demo.travelportuniversalapi.com/(S(cexfuhghvlzyzx5n0ysesra1))/Search'
#this varies every 20 minutes
data = None
headers = {'User-Agent': self.ua}
request = urllib2.Request(url, data, headers)
self.session.add_cookie_header(request)
response = urllib2.urlopen(request)
self.session.extract_cookies(response, request)
url = response.geturl()
data = {'From': 'lhr', 'To': 'ams', 'Departure' :
'9/4/2013','Return' : '9/6/2013'}
headers = {'User-Agent': self.ua, "Content-type":
"application/x-www-form-urlencoded; charset=UTF-8",
}
request = urllib2.Request(url, urllib.urlencode(data),
headers, 20)
self.session.add_cookie_header(request)
response = urllib2.urlopen(request, timeout=30) #HTTP
Error 404: Not Found - aici am eroare
self.session.extract_cookies(response, request)
except urllib2.URLError as e:
print >> sys.stderr, e
return None
rt = website()
rt.get()
The error that i receive at the last urllib2.Request is HTTP Error 404:
Not Found. I am not sure my cookies are working. Monitoring HTTP packets
with an addon in the browser I noticed the following header when the POST
is sent in a broswer: 'X-Requested-With XMLHttpRequest' - is this
relevant?
Thank you, Regards, Nicoara
The problem that I have - and try to solve with Python - is to make
consecutive POST requests (completing an online form) for a website
(specifically, a free online demo of an api at
demo.travelportuniversalapi.com). I am not able to acquire the results
page so far - been at this for two days now.
The code I employ is:
import sys
import urllib, urllib2, cookielib
from BeautifulSoup import BeautifulSoup
import re
class website:
def __init__(self):
self.host = 'demo.travelportuniversalapi.com'
self.ua = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0)
Gecko/20100101 Firefox/23.0'
self.session = cookielib.CookieJar() #session devine o
instanta a obiectului cookielib
pass
def get(self):
try:
url =
'http://demo.travelportuniversalapi.com/(S(cexfuhghvlzyzx5n0ysesra1))/Search'
#this varies every 20 minutes
data = None
headers = {'User-Agent': self.ua}
request = urllib2.Request(url, data, headers)
self.session.add_cookie_header(request)
response = urllib2.urlopen(request)
self.session.extract_cookies(response, request)
url = response.geturl()
data = {'From': 'lhr', 'To': 'ams', 'Departure' :
'9/4/2013','Return' : '9/6/2013'}
headers = {'User-Agent': self.ua, "Content-type":
"application/x-www-form-urlencoded; charset=UTF-8",
}
request = urllib2.Request(url, urllib.urlencode(data),
headers, 20)
self.session.add_cookie_header(request)
response = urllib2.urlopen(request, timeout=30) #HTTP
Error 404: Not Found - aici am eroare
self.session.extract_cookies(response, request)
except urllib2.URLError as e:
print >> sys.stderr, e
return None
rt = website()
rt.get()
The error that i receive at the last urllib2.Request is HTTP Error 404:
Not Found. I am not sure my cookies are working. Monitoring HTTP packets
with an addon in the browser I noticed the following header when the POST
is sent in a broswer: 'X-Requested-With XMLHttpRequest' - is this
relevant?
Thank you, Regards, Nicoara
Update if variables exist else echo an error message?
Update if variables exist else echo an error message?
How can I make this script to where if it finds that the fname and lname
do not exist that it will pop up a message saying that they never signed
in.
<?php
session_start();
include_once("connect.php");
date_default_timezone_set("America/Winnipeg");
$date = ("m-d-Y");
$timeout = date("g:i:s a");
if ("SELECT EXISTS(SELECT * FROM signin_out WHERE
lname='".$_POST['lastname']."' AND
fname='".$_POST['firstname']."'
AND date='".$date."')") {
mysql_query("UPDATE signin_out SET timeout='" . $timeout . "'
WHERE lname='" . $_POST['lastname'] . "' AND fname='" .
$_POST['firstname'] . "' AND timeout='' ");
header("Location: ../index.html");
} else {
echo "<script type='text/javascript>'";
echo "alert('<p>Oops! You never signed in!</p><br><p>Please contact a
Librarian</p>');'";
echo "</script>'";
header('Location: ../index.php?notsignedin');
}
?>
This is an intranet site for a highschool.
How can I make this script to where if it finds that the fname and lname
do not exist that it will pop up a message saying that they never signed
in.
<?php
session_start();
include_once("connect.php");
date_default_timezone_set("America/Winnipeg");
$date = ("m-d-Y");
$timeout = date("g:i:s a");
if ("SELECT EXISTS(SELECT * FROM signin_out WHERE
lname='".$_POST['lastname']."' AND
fname='".$_POST['firstname']."'
AND date='".$date."')") {
mysql_query("UPDATE signin_out SET timeout='" . $timeout . "'
WHERE lname='" . $_POST['lastname'] . "' AND fname='" .
$_POST['firstname'] . "' AND timeout='' ");
header("Location: ../index.html");
} else {
echo "<script type='text/javascript>'";
echo "alert('<p>Oops! You never signed in!</p><br><p>Please contact a
Librarian</p>');'";
echo "</script>'";
header('Location: ../index.php?notsignedin');
}
?>
This is an intranet site for a highschool.
Pandas pd.merge "TypeError: string indices must be integers, not str"
Pandas pd.merge "TypeError: string indices must be integers, not str"
I have researched this simple problem extensively but can't find an
answer. I am trying to merge two files using pandas' pd.merge based on a
common column named "JN". I believe it is treating my 'joined'
(os.path.join) filename as a string instead of a dataframe/csv file. After
I call the pd.merge function the error says "string indices must be
integers, not str".
import pandas as pd
import os
path = r"C:/Users/St/Documents/House/m2"
dirs = os.listdir(path)
for file in dirs:
if file.endswith("J.csv"):
J = file
if len(J) is 12: #some filenames are 12 chars others 11
jroot = J[:7]
else:
jroot = J[:6]
for file in dirs:
if file.endswith("2.csv"):
W = file
if len(W) is 12:
root2 = W[:7]
else:
root2 = W[:6]
JJ = os.path.join(path, J)
WW = os.path.join(path, W)
if jroot == root2: # if the first 7 (or 6) characters match, then
merge
JW = pd.merge(JJ, WW, on="JN")
In associated with the above pd.merge function call, I am getting this error:
TypeError: string indices must be integers, not str
I am wondering how to make it read my filename string as an actual file or
dataframe. JJ and WW are the equivalent to full paths when printed out. I
tried make these 'filenames' dataFrames using pd.DataFrame but wasn't able
to do so.
I have researched this simple problem extensively but can't find an
answer. I am trying to merge two files using pandas' pd.merge based on a
common column named "JN". I believe it is treating my 'joined'
(os.path.join) filename as a string instead of a dataframe/csv file. After
I call the pd.merge function the error says "string indices must be
integers, not str".
import pandas as pd
import os
path = r"C:/Users/St/Documents/House/m2"
dirs = os.listdir(path)
for file in dirs:
if file.endswith("J.csv"):
J = file
if len(J) is 12: #some filenames are 12 chars others 11
jroot = J[:7]
else:
jroot = J[:6]
for file in dirs:
if file.endswith("2.csv"):
W = file
if len(W) is 12:
root2 = W[:7]
else:
root2 = W[:6]
JJ = os.path.join(path, J)
WW = os.path.join(path, W)
if jroot == root2: # if the first 7 (or 6) characters match, then
merge
JW = pd.merge(JJ, WW, on="JN")
In associated with the above pd.merge function call, I am getting this error:
TypeError: string indices must be integers, not str
I am wondering how to make it read my filename string as an actual file or
dataframe. JJ and WW are the equivalent to full paths when printed out. I
tried make these 'filenames' dataFrames using pd.DataFrame but wasn't able
to do so.
Converting location into binary masks and filtering the image with such masks
Converting location into binary masks and filtering the image with such masks
Say that we have an image which pixels were labeled 1 and 2. How can we do
the following in MATLAB?
Convert the locations of 1s and 2s into binary masks
Filter the image with those masks
Thanks.
Say that we have an image which pixels were labeled 1 and 2. How can we do
the following in MATLAB?
Convert the locations of 1s and 2s into binary masks
Filter the image with those masks
Thanks.
Subscribe to:
Posts (Atom)