<?php
$connexion = new PDO('mysql:host='.'localhost'.';dbname='.'database', 'username', 'password');
$tag = (!empty($_GET['tag'])) ? "tag=".$connexion->quote(htmlentities($_GET['tag'], PDO::PARAM_STR)) : "1=1";
$cat = (!empty($_GET['cat'])) ? "cat=".$connexion->quote(htmlentities($_GET['cat'], PDO::PARAM_STR)) : "2=2";
$old = (!empty($_GET['old']) && $_GET['old']=="news" || $_GET['old']=="archives") ? htmlentities($_GET['old']) : "news";
$archives = $connexion->prepare("SELECT * FROM tags t INNER JOIN tagsarts ta ON (t.IDtag = ta.IDtj) INNER JOIN articles a ON (ta.IDaj=a.ID)
WHERE ".$tag." AND ".$cat." AND (NOW()-INTERVAL 1 MONTH)>a.date
GROUP BY a.ID ORDER BY a.date DESC;");
$news = $connexion->prepare("SELECT * FROM tags t INNER JOIN tagsarts ta ON (t.IDtag = ta.IDtj) INNER JOIN articles a ON (ta.IDaj=a.ID)
WHERE ".$tag." AND ".$cat." AND (NOW()-INTERVAL 1 MONTH)<a.date
GROUP BY a.ID ORDER BY a.date DESC;");
if ($old=="news") {
$news->execute();
while ($result = $news->fetch(PDO::FETCH_OBJ)) {
echo '<div id="artcomp'.$result->ID.'" class="artcomp"><br />';
echo '<h1 class="titre" id="titre'.$result->ID.'">' . $result->titre . '</h1><br />';
echo '<h5 class="date">' . $result->date . '</h5><br />';
echo '<div class="article">' . $result->content . '</div><br />';
echo '<h5 class="date">'.$result->tag.'</h5><br />';
echo '</div>';
}
$news->closeCursor();
} else {
$archives->execute();
while ($result = $archives->fetch(PDO::FETCH_OBJ)) {
echo '<div id="artcomp'.$result->ID.'" class="artcomp"><br />';
echo '<h1 class="titre" id="titre'.$result->ID.'">' . $result->titre . '</h1><br />';
echo '<h5 class="date">' . $result->date . '</h5><br />';
echo '<div class="article">' . $result->content . '</div><br />';
echo '</div>';
}
$archives->closeCursor();
}
?>
Tag Archive for engine
otacamyqe
googleã®æ¤œç´¢çµæžœæ•°ã‚’å–å¾—
#googleã®æ¤œç´¢çµæžœæ•°ã‚’見る
def countWord(word):
q = {#'q':'"'+question+'"',
'q':word.encode('utf-8'),
'v' : 1.0,
'hl' : 'ja',
'rsz': 'small'
}
url=u'http://ajax.googleapis.com/ajax/services/search/web?'+ urllib.urlencode(q)
json_result=urlfetch.fetch(url).content
json_result = string.replace(json_result, 'null', '"null"')
try:
dict_result=eval('dict('+json_result+')')
return dict_result['responseData']['cursor']['estimatedResultCount']
except:
return 0
twitterã®sinceã®æ—¥æ™‚フォーマットã®ä½œæˆ
def sinceParm(d):
#曜日
date = decoThree(d.strftime("%A"))
#æ—¥ã«ã¡
day = decoDay(d.strftime("%d"))
#月
mth = decoThree(d.strftime("%B"))
#年日時
ytime = d.strftime("%Y+%H %M %S")
ytime = ytime.replace(' ','%3A')
return date + "%2C+"+ day + "+" + mth + "+" + ytime + "+GMT"
def decoDay(day):
if (day[0] == "0"):return day[1]
else:return day
def decoThree(string):
deco = string[0]+string[1]+string[2]
return deco
wikipediaã«å˜èªžãŒã‚ã‚‹ã‹ã©ã†ã‹ã®ãƒã‚§ãƒƒã‚¯
def checkWiki(word):
if word != '':
url = 'http://ja.wikipedia.org/wiki/'+urllib.quote(word.encode('utf-8'))
#getHtml=unicode(urlfetch.fetch(url).content,'cp932')
getHtml=urlfetch.fetch(url).content
html_analyzed = BeautifulSoup(getHtml)
for node in html_analyzed.findAll('div', {'class': 'plainlinks'}):
#print >>sys.stderr,'node=%s'%node('b')[0](text = True)[0]
if node('b')[0](text = True)[0].find(u'ã‚りã¾ã›ã‚“')==-1:
print >>sys.stderr,'yes'
return 1
else:
print >>sys.stderr,'ng'
return 0
return 1
else:return 0
twitterã§è‡ªåˆ†ã®followerã‚’å–å¾—
def getFollowers():
#url作æˆ
followers=[]
url = 'http://twitter.com/statuses/followers.xml'
print >>sys.stderr,url
base64string =b64encode("%s:%s" % (username, password))
headers = {"Authorization": "Basic %s" % base64string}
xml_result=urlfetch.fetch(url, payload='', method=urlfetch.POST, headers=headers).content
for soup in BeautifulSoup(xml_result)('screen_name'):
#print >>sys.stderr,soup(text = True)[0]
followers.append(soup(text = True)[0])
return followers
twitter-apiã«ã‚ˆã‚‹è‡ªåˆ†ã‚¢ã‚«ã‚¦ãƒ³ãƒˆã¸ããŸè¿”ä¿¡ã®å–å¾—
#Twitterã‹ã‚‰ã‚るユーザã®ç›´è¿‘ã®è³ªå•ã‚’ã¨ã£ã¦ãã‚‹
import datetime
import locale
from datetime import timedelta
def GetresponseTwitter():
#url作æˆ
d=datetime.datetime.today()
dt1 = timedelta(seconds=60*60*9)#twitterã®æ™‚刻ã¯9時間å‰
dt2 = timedelta(seconds=const_time)
new_d = d-dt1-dt2#10分å‰ã®æ™‚刻をå–å¾—
since=sinceParm(new_d)#sinceパラメータã®ä½œæˆ
url = 'http://twitter.com/statuses/replies.xml?since=%s'%since
base64string =b64encode("%s:%s" % (username, password))#username,passwordã¯è‡ªåˆ†ã§å®šç¾©ã™ã‚‹ã“ã¨
headers = {"Authorization": "Basic %s" % base64string}
xml_result=urlfetch.fetch(url, payload='', method=urlfetch.POST, headers=headers).content
result=[]
for soup in BeautifulSoup(xml_result)('status'):
try:
print >>sys.stderr,'text=%s'%htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
text=htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
except:
print >>sys.stderr,'text=%s'%htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
text=htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
user=htmlentity2unicode(soup('screen_name')[0](text = True)[0])
result.append([text,user])
return result
NFO Render Engine
<?php
function output_nfo_image ($filename, $size) {
$font_file = "C:/WINDOWS/Fonts/cour.ttf";
$nfo_file_lines = file($filename);
$width = 0;
for($i = 0; $i < count($nfo_file_lines); $i++) {
$box = imagettfbbox($size, 0, $font_file, $nfo_file_lines[$i]);
$width = max($width, $box[2]);
}
$image = imagecreate($width, $size * (count($nfo_file_lines) + 1));
$background_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 255, 255, 255);
for($i = 0; $i < count($nfo_file_lines); $i++) {
imagettftext($image, $size, 0, 0, $size * ($i + 1), $text_color, $font_file, $nfo_file_lines[$i]);
}
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
//Calls the function to render "myfile.nfo" in image size "10".
output_nfo_image("myfile.nfo", 10);
?>
Sterling Job Search
{doctype}
<head>
{embed="site/_global_head_title"}
{css}
</head>
<body class="home">
<div id="container">
<div id="content">
<div id="content-main">
<form name="frm_jobsearch" method="get" action="">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="arialsm">Specialty</td>
<td>
<select name="specialty" class="arialsm">
<option value="Any">Any</option>
<option value="Emergency Medicine">Emergency Medicine</option>
</select></td>
</tr>
<tr>
<td class="arialsm">Profession</td>
<td>
<select name="profession" class="arialsm">
<option value="Any">Any</option>
<option value="Doctor of Osteopathy">Doctor of Osteopathy</option>
<option value="Medical Doctor">Medical Doctor</option>
<option value="Nurse Practitioner">Nurse Practitioner</option>
<option value="Physician Assistant">Physician's Assistant</option>
</select></td>
</tr>
<tr>
<td class="arialsm">State</td>
<td>
<select name="state" class="arialsm">
<option value="Any">Any</option>
<option value="Alabama">Alabama</option>
<option value="Arkansas">Arkansas</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Illinois">Illinois</option>
<option value="Louisiana">Louisiana</option>
<option value="Michigan">Michigan</option>
<option value="Ohio">Ohio</option>
<option value="Tennessee">Tennessee</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Search" class="arialsm" /></td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td> </td>
<td><a href="/jobs?specialty=&profession=&state=">View all jobs</a></td>
</tr>
</table>
</form>
<?php
if($_GET['specialty'] == "Any")
{
$specialty = 'Emergency Medicine';
} else {
$specialty = $_GET['specialty'];
}
if($_GET['profession'] == "Any")
{
$profession = 'Medical Doctor|Doctor of Osteopathy|Nurse Practitioner';
} else {
$profession = $_GET['profession'];
}
if($_GET['state'] == "Any")
{
$state = 'Florida|Alabama|Michigan';
} else {
$state = $_GET['state'];
}
?>
{exp:weblog:entries weblog="jobs" limit="25" rdf="off" dynamic="off" disable="categories|member_data|pagination|trackbacks" search:specialty="<?= $specialty ?>" search:profession="<?= $profession?>" search:state="<?= $state?>"}
<div class="item">
<ol>
<li>{title}</li>
<li>{description}</li>
<li>{specialty}</li>
<li>{profession}</li>
<li>{state}</li>
</ol>
<div>
{/exp:weblog:entries}
</div> <!-- close #content-main -->
</div> <!-- close #content -->
</div> <!-- close #container -->
</body>
</html>
Add a JSONProperty to your Model to save a dict to the datastore
from google.appengine.ext import db
from google.appengine.api import datastore_types
from django.utils import simplejson
class JSONProperty(db.Property):
def get_value_for_datastore(self, model_instance):
value = super(JSONProperty, self).get_value_for_datastore(model_instance)
return self._deflate(value)
def validate(self, value):
return self._inflate(value)
def make_value_from_datastore(self, value):
return self._inflate(value)
def _inflate(self, value):
if value is None:
return {}
if isinstance(value, unicode) or isinstance(value, str):
return simplejson.loads(value)
return value
def _deflate(self, value):
return simplejson.dumps(value)
data_type = datastore_types.Text
class Person(db.Model):
address_book = JSONProperty()
person = Person(address_book = {
"alice": { "phone": "555-555-5555", "email": "alice@example.com" } })
person.address_book["bob"] = { "email": "bob@example.com" }
person.put()
...
some_person = db.get(key)
logging.info("Phone number for alice is " + some_person.address_book["alice"]["phone"])
Transactionã«ã¤ã„㦠2
class MyModel1(db.Model):
title = StringProperty()
class MyModel2(db.Model):
ref = ReferenceProperty(MyModel1)
otherRef = ReferenceProperty(OtherModel)
def method():
model1 = MyModel1.get_by_id(int(idString))
model2s = MyModel2.gql("WHERE ref = :ref", ref=model1)
db.run_in_transaction(delete_cascade, model1, model2s)
def delete_cascade(model1, model2s)
db.delete(model2s)
model1.delete()