SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#101 2014-12-16 13:23:11

PeterIHughes
New Member
Registered: 2014-12-15
Posts: 5

Re: HOW TO : using lua scripts in conky

arclance wrote:

You can use "io.popen" to run scripts in other languages and send the results to the Lua script.
I use Python for things that can't be done or are too difficult or complicated to do in Lua that way.

Thanks for your help,

I am going to try that out.

Offline

Be excellent to each other!

#102 2014-12-16 20:56:57

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,022

Re: HOW TO : using lua scripts in conky

PeterIHughes wrote:
arclance wrote:

You can use "io.popen" to run scripts in other languages and send the results to the Lua script.
I use Python for things that can't be done or are too difficult or complicated to do in Lua that way.

Thanks for your help,

I am going to try that out.

Well I've written exactly what you want: lua-shellio. If it can be used from within conky, that is. It's based on my lua-filterpipe (which is a dependency). Other than that, it requires lua-posix (sudo apt-get install lua-posix).


RTFM | Life is too short for man pages, but occasionally much too short without them.

Offline

#103 Yesterday 15:28:17

PeterIHughes
New Member
Registered: 2014-12-15
Posts: 5

Re: HOW TO : using lua scripts in conky

This is what I have so far

I created a python script to take the contents of the raw lunar data file
and rewrite it as-is but with new lines inserted following the date in 2014-12-31 format
as a date in Tuesday December 16th 2014 format

the daysuffix function is used to add the st, nd, rd or th after the day number
leading zeros are stripped from the day number

the raw file which originally looked like this
from line16
New Moon
on
2014-11-22
12:32

now looks like this
New Moon
on
2014-11-22
Saturday, November 22nd 2014
12:32


So this script will be run once following the retrieval of the data files
from lunaf.com (per this post - Conky weather+moon scripts)
at the beginning of the conky

Then in the TEXT section, I will replace
${execpi 600 sed -n '18p' $HOME/5_Moon/today}
with
${execpi 600 sed -n '19p' $HOME/5_Moon/raw}

The conky will then display Saturday, November 22nd 2014 instead of 2014-11-22 for the new moon date (etc for all dates)


the python script

# read Lunar raw file
# for each date in 2014-12-31 format
# write a new line after in Tuesday December 31st 2014 format

import sys
import fileinput
from datetime import datetime

def main():
   # read each line of the file
   for i, line in enumerate(fileinput.input('your raw file', inplace=1)):
      sys.stdout.write(line)

      # write full text date after the NEW MOON date line
      if i == 17:
         sys.stdout.write(gettextdate(datetime.strptime(line[:-1], '%Y-%m-%d')) + '\n')

      # write full text date after the 1ST QUARTER date line
      if i == 23:
         sys.stdout.write(gettextdate(datetime.strptime(line[:-1], '%Y-%m-%d')) + '\n')

      # write full text date after the FULL MOON date line
      if i == 29:
         sys.stdout.write(gettextdate(datetime.strptime(line[:-1], '%Y-%m-%d')) + '\n')

      # write full text date after the LAST QUARTER date line
      if i == 35:
         sys.stdout.write(gettextdate(datetime.strptime(line[:-1], '%Y-%m-%d')) + '\n')

      # write full text date after the NEW MOON (NEXT) date line
      if i == 41:
         sys.stdout.write(gettextdate(datetime.strptime(line[:-1], '%Y-%m-%d')) + '\n')

   return "MAIN DONE"

def gettextdate(datetime):

   return '{0:%A}'.format(datetime) + ', {0:%B}'.format(datetime) + ' ' + '{0:%d}'.format(datetime).lstrip("0") + daysuffix(datetime) + ' {0:%Y}'.format(datetime)



def daysuffix(t):
   daysuffs = ["  ", "st", "nd", "rd", "th", "th", "th", "th", "th", "th",
               "th", "th", "th", "th", "th", "th", "th", "th", "th", "th",
               "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th",
               "th", "st"]
   return daysuffs[t.day]



if __name__ == "__main__":
   print('STARTING MAIN')
   print(' ')
   print(' ')
   msg = main()
   print(' ')
   print(' ')
   print(msg)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo