RandomNews - Limit by Date?

All new Coranto Addons, updates and patches to addons, will be released here...also, get support for addons within!

Moderators: Spunkmeyer, Dale Ray, SrNupsen, Bluetooth, Jackanape

RandomNews - Limit by Date?

Postby web » Sun Oct 07, 2007 11:07 am

Is it possible to limit randomization by days?
i have more then 1000 news in my database. when randomizing, it shows me old news. i want to limit it by the current day, or even by the last hours.
Is it possible?
if not, what any other solution could be used?
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Postby Dale Ray » Sun Oct 07, 2007 4:03 pm

After looking at the RandomNews addon The quickest way - with the least coding - to limit the selection of items would be to create a profile that uses a style that duplicates the format of newdat.txt. Have the profile build the news in the same directory as newsdat.txt.

Then change the file name in this line of cra_randomnews.pl:
$filehandle = $addon->open("$CConfig{'htmlfile_path'}/newsdat.txt");

to the name of the file your profile is building.

This will allow you to limit the items that RandomNews uses by any of the filters that you can use in a profile including date.

Each news field in newsdat.txt is separated by the characters ``x. Your style would have to list every news field you use, in the same order as they are listed in newsdat.txt with the ``x separating each news field. You can find the list of newsfields and the order in a line looking like this:
@fieldDB = (q~Subject~, q~Text~, q~CustomField_qwerty~, q~);

in crcfg.dat.

You end up with a style that is all on one line and looks like:

Code: Select all
<Field: Subject>``x<Field: User>``x<Field: Text>``x<Field: newsid>``x<Field: newstime>``x<Field: CustomField_qwerty>``x<Field: Category>``x


As you can see in this style the User, newsid, newstime, and Category fields are added.

Remember to put a carriage return at the end of the line.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Dale Ray » Sun Oct 07, 2007 4:12 pm

If you use this method remember that for items to appear in the file that RandomNews is using you have to build news. RandomNews usually uses the raw newsdat.txt. This is an advantage if you want approval over items before they can be viewed and a disadvantage if want items available as soon as they are input.

Using this method gives you the ability to filter the available items with any of the tools you can use on any profile.

Also, I tested this briefly on a local install and it worked for me in that limited testing.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby web » Sun Oct 07, 2007 4:50 pm

Thanks, but I'm not using newsdat.txt, but MySQL.
Additional news building is a big disadvantage for me. I'm adding 50-70 news daily.

Maybe there are other ways?
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Postby Dale Ray » Sun Oct 07, 2007 5:00 pm

web wrote:Thanks, but I'm not using newsdat.txt, but MySQL.
Additional news building is a big disadvantage for me. I'm adding 50-70 news daily.

Maybe there are other ways?


That info was kind of important for anyone attempting to answer your question. But I didn't waste my time as I learned something new from the process of figuring out an answer.

You should be able to modify the database query in cra_randomnews.pl.

Code: Select all
         if (defined($in{"category"})) {
            $query = "SELECT * FROM $CConfig{CorantoSQL_tblname} WHERE Category = '".$in{"category"}."'";
         }
         else {
            $query = "SELECT * FROM $CConfig{CorantoSQL_tblname}";
         }
         $sth = $corantosql_dbh->prepare($query);
         $sth->execute();
         while ($corantosql_ref = $sth->fetchrow_hashref()) {
            @csqldata = ();
            GetSQLFields();
            for $i (@fieldDB_internalorder) {
               push @csqldata,$$i;
            }
            push @newsdata,join '``x',@csqldata;
         }


You can see that the query is limited if you choose a category, maybe you can do something similar for the date? Since you are using MySQL you probably have a better understanding of database queries than I do.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Dale Ray » Sun Oct 07, 2007 5:04 pm

It just occured to me - since you are using MySQL you don't even need the RandomNews addon. You should be able to generate a random item directly from a database query.

Like this example or this one with an added limit on the value of the date field?
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby web » Sun Oct 07, 2007 5:57 pm

Thanks. I'll check them, but seems it must work perfectly.

mostly i liked that one
Code: Select all
$query = "SELECT * FROM $CConfig{CorantoSQL_tblname} WHERE Category = '".$in{"category"}."'";

there is possibillity to add a date as filter too
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Postby Jackanape » Sun Oct 07, 2007 6:41 pm

web wrote:there is possibillity to add a date as filter too


It should be simple, depending on your database table...do you have a date row in your table? Then, you could do this:
Code: Select all
$query = "SELECT * FROM $CConfig{CorantoSQL_tblname}
WHERE Category = '".$in{"category"}."'"
AND daterow > "{earliest date you want to use}
LIMIT {number of newsstories you want to fecth};


just as a rough outline.
A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly.
Specialization is for insects.
-Robert A. Heinlein
User avatar
Jackanape
 
Posts: 632
Joined: Tue Jan 09, 2007 12:15 am
Location: Capitol of the Great State of New York

Postby web » Sun Oct 07, 2007 6:53 pm

yeah, but I didn't find any date row in database
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Postby SrNupsen » Sun Oct 07, 2007 7:04 pm

Date is stored as unix time, so you'll need to convert it first.


I liked your first solution, Dale - very creative :)
Last edited by SrNupsen on Mon Oct 08, 2007 9:54 am, edited 1 time in total.
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby web » Sun Oct 07, 2007 7:25 pm

that's ok. i have a field newstime.
as I'm far away from any serious programming, can anybody say how to convert it programmatically?
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Postby Jackanape » Mon Oct 08, 2007 4:06 am

web wrote:that's ok. i have a field newstime.
as I'm far away from any serious programming, can anybody say how to convert it programmatically?


By field, you mean a row in your dB for newstime? That can do the same thing... :D
A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly.
Specialization is for insects.
-Robert A. Heinlein
User avatar
Jackanape
 
Posts: 632
Joined: Tue Jan 09, 2007 12:15 am
Location: Capitol of the Great State of New York

Postby web » Mon Oct 08, 2007 4:49 am

that means, that when I'll give a time filter it automatically recognizes time format?
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Postby SrNupsen » Mon Oct 08, 2007 9:56 am

No, you just have to decide on a date to filter on, convert it to Unix time using the link I gave you (which is now working as well), and then use the resulting Unix time as a time filter.
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby web » Mon Oct 08, 2007 10:08 am

ок. but i'm updating my site every day with more then 50 news.
DO you mean that i have to convert date every day and include myself it in script?
User avatar
web
 
Posts: 176
Joined: Sun Nov 30, 2003 3:39 pm

Next

Return to Addon Release and Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron