function monthNewsList() {
$query = "SELECT COUNT(id) total, MONTHNAME(date) month, YEAR(date) year ";
$query .= "FROM news ";
$query .= "GROUP BY MONTH(date), YEAR(date) ";
$query .= "ORDER BY date ";
$result = mysql_query($query);
$count = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
echo $row["month"].' '.$row["year"].' ('.$row["total"].")<br />
";
}
mysql_free_result($result);
}
Tag Archive for count
Posts by month
Count directory entries in given directories
#!/usr/bin/perl
$ARGV[0] = '.' unless @ARGV;
for my $dir (@ARGV) {
opendir DIR, $dir or die "$dir: $!
";
$file =~ m:^.: or ++$count
while ($file = readdir DIR);
closedir DIR;
}
print "$count
";
exit 0;
Count the number of files in a directory
find . | wc -l
Counting files in subdirs
find . -name '.svn' -prune -or -maxdepth 2 -type d -print -exec sh -c 'find {} -name ".svn" -prune -or -print | wc -l' ;
Count files and directories
F_CNT=0 D_CNT=0 for FILE in *; do test -f "$FILE" && F_CNT=`expr $F_CNT + 1` test -d "$FILE" && D_CNT=`expr $D_CNT + 1` done echo "$F_CNT files & $D_CNT dirs in current directory."
Python – Cattura tutti i links
import os,re,sys
# python script.py file.html
links = re.compile('[<].?[Aa].*[Hh][Rr][Ee][Ff].*=.*["']?.*["']?.?[>]')
lunghezza_file = os.stat(sys.argv[1])[6]
f = open(sys.argv[1], 'r')
while(lunghezza_file > 0):
riga = f.readline()
lunghezza_file -= len(riga)
if links.search(riga):
comparazione = links.search(riga)
output = comparazione.group(0)
links2 = re.compile('http:-*[Zz][Ii][Pp]')
if links2.search(output):
output2 = links2.search(output)
print output2.group(0)
print 'FATTO'
Category: Uncategorized |
Tags: cli, count, dangerous, default, delicious, dictionary, documentation, hello, python, regex, world
Python – Stampa i links di una pagina HTML
import re,sgmllib,sys,urllib
class Parser(sgmllib.SGMLParser):
def start_a(self, attr):
regx = re.compile('[Hh][Tt][Tt][Pp].*....$')
href = [v for a, v in attr if a == 'href']
try:
if regx.match(href[0]): print href[0]
except:
pass
if __name__ == '__main__':
try:
fd = urllib.urlopen(sys.argv[1])
parser = Parser()
parser.feed(fd.read())
parser.close()
fd.close()
except Exception, error:
print 'Errore: ' + str(error)
Category: Uncategorized |
Tags: cli, count, dangerous, default, delicious, dictionary, documentation, hello, python, regex, world
Python – Uso di wx.PostEvent
import wx, thread, time def EVT_RESULT(win,func): win.Connect(-1,-1,111,func) class RESULT(wx.PyEvent): def __init__(self, data): wx.PyEvent.__init__(self) self.SetEventType(111) self.data = data class Main_Frame(wx.Frame): def __init__(self, parent=None, id=-1, title='Example PostEvent...'): self.ID_S = wx.NewId() self.ID_ST = wx.NewId() wx.Frame.__init__(self, parent, id, title) self.CenterOnScreen() self.Show() self._panel = wx.Panel(parent=self, id=-1) self._bu = wx.Button(parent=self._panel, id=self.ID_S, label='OK', size=(100, 100)) self.Bind(wx.EVT_BUTTON, self.OnStart, id=self.ID_S) self._bo = wx.Button(parent=self._panel, id=self.ID_ST, label='KO',pos=(0, 200), size=(100, 100)) self.Bind(wx.EVT_BUTTON, self.OnStop, id=self.ID_ST) EVT_RESULT(self, self.OnR) self.CreateStatusBar() def OnR(self, event): self.SetStatusText(str(event.data)) def OnStart(self, evt): thread.start_new_thread(self.avvia, (self,)) def OnStop(self, evt): print 'Cliccato....' def avvia(self, n): for i in range(10): time.sleep(1) wx.PostEvent(n, RESULT(i)) class Main_App(wx.App): def OnInit(self): self._main_frame = Main_Frame() self.SetTopWindow(self._main_frame) return True if __name__ == '__main__': main_app = Main_App() main_app.MainLoop()
Category: Uncategorized |
Tags: cli, count, dangerous, default, delicious, dictionary, documentation, hello, python, regex, world
Python – create daemon
def createDaemon():
'''Funzione che crea un demone per eseguire un determinato programma...'''
import os
# create - fork 1
try:
if os.fork() > 0: os._exit(0) # exit father...
except OSError, error:
print 'fork #1 failed: %d (%s)' % (error.errno, error.strerror)
os._exit(1)
# it separates the son from the father
os.chdir('/')
os.setsid()
os.umask(0)
# create - fork 2
try:
pid = os.fork()
if pid > 0:
print 'Daemon PID %d' % pid
os._exit(0)
except OSError, error:
print 'fork #2 failed: %d (%s)' % (error.errno, error.strerror)
os._exit(1)
funzioneDemo() # function demo
def funzioneDemo():
import time
fd = open('/tmp/demone.log', 'w')
while True:
fd.write(time.ctime()+'
')
fd.flush()
time.sleep(2)
fd.close()
if __name__ == '__main__':
createDaemon()
Category: Uncategorized |
Tags: c, cli, count, daemon, dangerous, default, delicious, dictionary, documentation, fork, hello, python, world