Use Mechanize to submit new entry

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Use Mechanize to submit new entry

Post by glkc »

Hi,

When I try to use WWW::Mechanize to submit a new entry to the s9y blog, I see there are two unnamed submit options,
<NONAME>=- Preview - (submit)
<NONAME>=- Save - (submit)

and function submit() doesn't work.

Is there any way to name the submit buttons so Mechanize may work? Thanks,

--George
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Use Mechanize to submit new entry

Post by garvinhicking »

Hi!

I don't know WWW:Mechanize. But in javascript, you would simply do a document.getElementById('serendipityEntry').submit().

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

My test seems half working now.

I can see an entry was on database in table serendipity_entries, but It doesn't display on the weblog. Where should I check? Thanks,
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Use Mechanize to submit new entry

Post by garvinhicking »

Hi!

How does the SQL dump for that entry look like? Maybe some fields are wrong like "isdraft" or "timestamp"?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

Hi

Thank you Garvin. Following is an output from the entries:

mysql> select * from serendipity_entries where id=27989 or id=27988;
+-------+-------------------------------+------------+-------------------------------+----------+------------+----------+--------+----------------+----------+---------+----------------+---------------+-------------------+
| id | title | timestamp | body | comments | trackbacks | extended | exflag | author | authorid | isdraft | allow_comments | last_modified | moderate_comments |
+-------+-------------------------------+------------+-------------------------------+----------+------------+----------+--------+----------------+----------+---------+----------------+---------------+-------------------+
| 27988 | This is a test. please ignore | 1246558600 | This is a test. please ignore | 0 | 0 | | 0 | first.user | 112 | false | true | 1246558600 | false |
| 27989 | 18z frzlvls done | 1246559730 | | 0 | 0 | | 0 | second.user | 78 | false | false | 1246559730 | false |
+-------+-------------------------------+------------+-------------------------------+----------+------------+----------+--------+----------------+----------+---------+----------------+---------------+-------------------+
2 rows in set (0.00 sec)

Where id=27988, which is entered from an automatic script, is not displayed on the weblog;
id=27989, which is entered from web interface, is displayed.

Thank you.

--George
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Use Mechanize to submit new entry

Post by garvinhicking »

Hi!

Is the entry displayed within the backend? The only thing that seems to differ is the "exflag" column, which shouldn't make a difference.

If you use the same authorids, does that make a difference?

Also, check the serendipity_entrycat and serendipity_entryproperties DB tables, if they differ a lot from what they have on their entry_id relations? And you might want to check the _permalinks DB table to see if it has reeceveid an entry.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

There is no entryid for 27988 on the _entrycat DB tables, but everything looks normal on the _entryproperties and _permalinks DB tables.

mysql> select * from serendipity_entrycat where entryid=27989 or entryid=27988;
+---------+------------+
| entryid | categoryid |
+---------+------------+
| 27989 | 1 |
+---------+------------+
1 row in set (0.00 sec)

Thanks.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Use Mechanize to submit new entry

Post by garvinhicking »

Hi!

Did you maybe try to add a entryid=27989, category=1 entry inside the database? Which s9y version are you using and which plugins? Usually entries without a category should be displayed, but if you use the categorytemplates or startcat plugin for example, those could set a fixed category and this leads to your entry not being displayed.

Also, did you read my questiona bout whether the entry is displayed in the backend?
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

That's a quick reply. I'll test the add entryid first.
Also in the form, there is a variable like this
serendipity[categories][]=<UNDEF> (option) [*<UNDEF>/off|16/Announcements]

I entered it like
serendipity[categories][]=16 (option) [<UNDEF>/off|*16/Announcements]

It seems no help.

For the backend question, do you refer to a different thread in the forum or just in this thread?

Thanks a lot.
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

The entry was displayed after the entryid was added into *entrycat. Thanks

Also, the s9y version is very old. It is 1.0.1. How do I check the plugins? Thanks
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Use Mechanize to submit new entry

Post by garvinhicking »

Hi!

Hm, sadly I don't know how to specify things in mechanize; but the HTTP POST var needs to be serendipity[categories][]=16, yes. Then it should create a entrycat id for "16".

With backend I mean, when you go to the s9y admin panel > Edit entries, do you see the created entry?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

Yes. They are there. Also, I can find them from quick search. Thanks
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Use Mechanize to submit new entry

Post by garvinhicking »

Hi!

Oh, okay. s9y 1.0.1 is VERY VERY old, you should really try to upgraed; the HTTP POST issues could very much likely be associated.

1.0. is about 3 years old...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
glkc
Regular
Posts: 10
Joined: Wed Jun 17, 2009 4:59 pm

Re: Use Mechanize to submit new entry

Post by glkc »

Hi Garvin,

Thanks for your helps. Finally I think it is working. I didn't put a "=" after field("serendipity[categories][]" and that caused problems.

$mech->field("serendipity[body]", "This is a test. please ignore" );
#$mech->field("serendipity[categories][]", "13" ); This line doesn't work
$mech->field("serendipity[categories][]=", 13); This line works

Although the dump form shows same result, i.e.,

serendipity[categories][]=13 (option) [<UNDEF>/off|*13]


Thank you again for your help.

--George
Post Reply