Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WordPressSharp.Models;
- using WordPressSharp;
- using WordPressSharp.Constants;
- using System.Net;
- using KBCsv;
- namespace wp_sharp
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- /*
- var post = new Post
- {
- PostType = "post",
- Title = "My Awesome Post",
- Content = "This is the content",
- PublishDateTime = DateTime.Now
- };
- using (var client = new WordPressClient(new WordPressSiteConfig
- {
- BaseUrl = "http://wps.ru",
- Username = "admin",
- Password = "123",
- BlogId = 1
- }))
- {
- //var id = Convert.ToInt32(client.NewPost(post));
- }
- */
- foreach (string item in GetTitle())
- {
- if (isPost(item.ToString()) == false)
- {
- NewPost(item);
- MessageBox.Show(item+" +");
- }
- else
- {
- MessageBox.Show("Уже есть в базе");
- }
- }
- }
- public static void NewPost(string title)
- {
- var post = new Post
- {
- PostType = "post",
- Title = title,
- Content = "This is the content",
- Status = "publish",
- PublishDateTime = DateTime.Now
- };
- using (var client = new WordPressClient(new WordPressSiteConfig
- {
- BaseUrl = "http://wps.ru",
- Username = "admin",
- Password = "123",
- BlogId = 1
- }))
- {
- var id = Convert.ToInt32(client.NewPost(post));
- }
- }
- public static bool isPost(string title)
- {
- using (var client = new WordPressClient(new WordPressSiteConfig
- {
- BaseUrl = "http://wps.ru",
- Username = "admin",
- Password = "123",
- BlogId = 1
- }))
- {
- PostFilter r = new PostFilter();
- r.PostType = "post";
- Post[] ten = client.GetPosts(r);
- foreach (Post ipost in ten)
- {
- if (ipost.Title == title)
- {
- return true;
- }
- }
- }
- return false;
- }
- public static List<string> GetTitle()
- {
- List<string> list = new List<string>();
- WebClient wb = new WebClient();
- string html = wb.DownloadString("https://hit.ua/site_search/99424?csv=1");
- var csv = html;
- using (var reader = CsvReader.FromCsvString(csv))
- {
- reader.ValueSeparator = ';';
- while (reader.HasMoreRecords)
- {
- var dataRecord = reader.ReadDataRecord();
- list.Add(CapitalizeFirstLetter(dataRecord[1]));
- }
- }
- return list;
- }
- public static string CapitalizeFirstLetter(string s)
- {
- if (String.IsNullOrEmpty(s))
- return s;
- if (s.Length == 1)
- return s.ToUpper();
- return s.Remove(1).ToUpper() + s.Substring(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement